deezer/spleeter · error · ValueError

n_chunks_per_song must be positif

Error message

n_chunks_per_song must be positif

What it means

compute_segments validates n_chunks_per_song before slicing a dataset into per-song chunk datasets. If the value is zero or negative, there would be zero map iterations and no meaningful segmentation, so it raises ValueError immediately. Note the message contains a typo ('positif'), which is how you can identify this exact check.

Source

Thrown at spleeter/dataset.py:433

        }
        return (input_, output)

    def compute_segments(self, dataset: Any, n_chunks_per_song: int) -> Any:
        """
        Computes segments for each song of the dataset.

        Parameters:
            dataset (Any):
                Dataset to compute segments for.
            n_chunks_per_song (int):
                Number of segment per song to compute.

        Returns:
            Any:
                Segmented dataset.
        """
        if n_chunks_per_song <= 0:
            raise ValueError("n_chunks_per_song must be positif")
        datasets = []
        for k in range(n_chunks_per_song):
            if n_chunks_per_song > 1:
                datasets.append(
                    dataset.map(
                        lambda sample: dict(
                            sample,
                            start=tf.maximum(
                                k
                                * (
                                    sample["duration"]
                                    - self._chunk_duration
                                    - 2 * self.MARGIN
                                )
                                / (n_chunks_per_song - 1)
                                + self.MARGIN,
                                0,
                            ),

View on GitHub (pinned to c8854001ac)

Solutions

  1. Pass a positive integer for n_chunks_per_song (>= 1)
  2. If you want no chunking, call compute_segments with n_chunks_per_song=1 rather than 0
  3. Validate/normalize the value at config-load time: max(1, int(n_chunks_per_song))
  4. Check upstream code that computes the value for off-by-one or empty-input bugs

Example fix

// before
compute_segments(dataset, n_chunks_per_song=0)
// after
compute_segments(dataset, n_chunks_per_song=1)
Defensive patterns

Strategy: validation

Validate before calling

def assert_positive_chunks(n):
    if not isinstance(n, int) or n <= 0:
        raise ValueError(f"n_chunks_per_song must be a positive int, got {n!r}")
    return n

assert_positive_chunks(n_chunks_per_song)  # call before compute_segments

Type guard

def is_positive_int(v) -> bool:
    return isinstance(v, int) and not isinstance(v, bool) and v > 0

Try / catch

try:
    segments = compute_segments(dataset, n_chunks_per_song=n)
except ValueError as e:
    if 'n_chunks_per_song' in str(e):
        logging.warning("Invalid n_chunks_per_song=%s, falling back to 1", n)
        segments = compute_segments(dataset, n_chunks_per_song=1)
    else:
        raise

Prevention

When it happens

Trigger: Calling compute_segments (directly or via the public build/entry API) with n_chunks_per_song=0 or a negative integer, e.g. from a miscomputed parameter or a config file where the chunk count was set to 0.

Common situations: Config files or CLI flags where the chunk count was computed by another expression that yielded 0; users assuming 0 means 'no chunking' when the API actually requires >= 1.

Related errors


AI-assisted analysis of deezer/spleeter@c8854001ac (2026-08-28). Data as JSON: /api/errors/92dcc064871424b3. Report an issue: GitHub.