tracel-ai/burn · error

{other:?} reduction is not supported

Error message

{other:?} reduction is not supported

What it means

Exhaustive-match guard in `GramMatrixLoss::forward`: only Mean/Auto and Sum reductions are implemented for the gram matrix loss; any other `Reduction` variant (e.g., a per-element or weighted reduction) reaches the wildcard arm and panics.

Source

Thrown at crates/burn-vision/src/loss/gram_matrix/gram_matrix_loss.rs:174

    ///
    /// let predictions = /* [N, 3, H, W] */;
    /// let targets = /* [N, 3, H, W] */;
    ///
    /// # Returns a tensor with shape [1] containing a single loss value
    /// let loss = loss_fn.forward(predictions, targets, Reduction::Mean);
    /// ```
    pub fn forward(
        &self,
        predictions: Tensor<4>,
        targets: Tensor<4>,
        reduction: Reduction,
    ) -> Tensor<1> {
        let unreduced_loss = self.forward_no_reduction(predictions, targets);

        match reduction {
            Reduction::Mean | Reduction::Auto => unreduced_loss.mean(),
            Reduction::Sum => unreduced_loss.sum(),
            other => panic!("{other:?} reduction is not supported"),
        }
    }

    /// Computes the unreduced Gram Matrix Loss per sample in the batch.
    ///
    /// # Arguments
    ///
    /// - `predictions` - The model's predicted images. The pixels should be in the \[0.0, 1.0\] range.
    /// - `targets` - The ground truth target images. The pixels should be in the \[0.0, 1.0\] range.
    ///
    /// # Returns
    ///
    /// A 1D tensor containing the total weighted loss for each sample in the batch.
    ///
    /// # Shapes
    ///
    /// - predictions: `[batch_size, 3, height, width]`
    /// - targets: `[batch_size, 3, height, width]`

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Use `Reduction::Mean` or `Reduction::Sum` when calling forward
  2. Apply the desired custom reduction manually on `forward_no_reduction` output
  3. Extend the match in gram_matrix_loss.rs if a new reduction is required
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/burn-vision/src/loss/gram_matrix/gram_matrix_loss.rs:174 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05). Data as JSON: /api/errors/145c104e0074258e. Report an issue: GitHub.