Unity-Technologies/ml-agents · error · TrainerConfigError

Threshold for next lesson cannot be negative when the measur

Error message

Threshold for next lesson cannot be negative when the measure is progress.

What it means

When a curriculum lesson uses MeasureType.PROGRESS, the completion threshold represents a fraction of lessons completed and must lie in [0.0, 1.0]. mlagents throws TrainerConfigError during config validation because a negative threshold is meaningless for progress-based advancement.

Source

Thrown at ml-agents/mlagents/trainers/settings.py:485

    measure: MeasureType = attr.ib(default=MeasureType.REWARD)
    min_lesson_length: int = 0
    signal_smoothing: bool = True
    threshold: float = attr.ib(default=0.0)
    require_reset: bool = False

    @threshold.validator
    def _check_threshold_value(self, attribute, value):
        """
        Verify that the threshold has a value between 0 and 1 when the measure is
        PROGRESS
        """
        if self.measure == self.MeasureType.PROGRESS:
            if self.threshold > 1.0:
                raise TrainerConfigError(
                    "Threshold for next lesson cannot be greater than 1 when the measure is progress."
                )
            if self.threshold < 0.0:
                raise TrainerConfigError(
                    "Threshold for next lesson cannot be negative when the measure is progress."
                )

    def need_increment(
        self, progress: float, reward_buffer: List[float], smoothing: float
    ) -> Tuple[bool, float]:
        """
        Given measures, this method returns a boolean indicating if the lesson
        needs to change now, and a float corresponding to the new smoothed value.
        """
        # Is the min number of episodes reached
        if len(reward_buffer) < self.min_lesson_length:
            return False, smoothing
        if self.measure == CompletionCriteriaSettings.MeasureType.PROGRESS:
            if progress > self.threshold:
                return True, smoothing
        if self.measure == CompletionCriteriaSettings.MeasureType.REWARD:
            if len(reward_buffer) < 1:

View on GitHub (pinned to 3ecb446f75)

Solutions

  1. Set the threshold to a value between 0.0 and 1.0 (e.g. 0.5 for advancing after 50% of episodes complete).
  2. If you intended reward-strength-based advancement, change measure to reward and use an appropriate reward threshold.
  3. Check for stray minus signs from templating or string concatenation when generating configs.

Example fix

// before
measure: progress
completion_criteria:
  threshold: -0.2
// after
measure: progress
completion_criteria:
  threshold: 0.3
Defensive patterns

Strategy: validation

Validate before calling

def validate_progress_threshold(measure, threshold):
    if measure == 'progress' and not (0.0 <= threshold <= 1.0):
        raise ValueError('progress threshold must be in [0.0, 1.0], got %r' % threshold)

Type guard

def is_valid_threshold(x):
    return isinstance(x, (int, float)) and 0.0 <= x <= 1.0

Try / catch

from mlagents.trainers.exception import TrainerConfigError
try:
    load_config(path)
except TrainerConfigError as e:
    logger.error('Invalid curriculum threshold: %s', e)

Prevention

When it happens

Trigger: A YAML/JSON curriculum defines a lesson with completion_criteria: threshold less than 0.0 while measure: progress (e.g. threshold: -0.5, a typo or copy-paste from a reward/progress-based config).

Common situations: Hand-editing curriculum configs, converting configs between measure types (reward thresholds can be negative, progress cannot), or templated config generation producing bad values.

Related errors


AI-assisted analysis of Unity-Technologies/ml-agents@3ecb446f75 (2026-09-02). Data as JSON: /api/errors/3a562e1c3f9bfab7. Report an issue: GitHub.