{"record":{"id":"e91a0a215a526ba9","repo":"sgl-project/sglang","slug":"passing-integer-indices-e-g-from-enumerate-time","errorCode":null,"errorMessage":"Passing integer indices (e.g. from `enumerate(timesteps)`) as timesteps to `FlowMatchEulerDiscreteScheduler.step()` is not supported. Make sure to pass one of the `scheduler.timesteps` as a timestep.","messagePattern":"Passing integer indices \\(e\\.g\\. from `enumerate\\(timesteps\\)`\\) as timesteps to `FlowMatchEulerDiscreteScheduler\\.step\\(\\)` is not supported\\. Make sure to pass one of the `scheduler\\.timesteps` as a timestep\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/schedulers/scheduling_flow_match_euler_discrete.py","lineNumber":492,"sourceCode":"            s_noise (`float`, defaults to 1.0):\n                Scaling factor for noise added to the sample.\n            generator (`torch.Generator`, *optional*):\n                A random number generator.\n            per_token_timesteps (`torch.Tensor`, *optional*):\n                The timesteps for each token in the sample.\n            return_dict (`bool`):\n                Whether or not to return a\n                [`~schedulers.scheduling_flow_match_euler_discrete.FlowMatchEulerDiscreteSchedulerOutput`] or tuple.\n\n        Returns:\n            [`~schedulers.scheduling_flow_match_euler_discrete.FlowMatchEulerDiscreteSchedulerOutput`] or `tuple`:\n                If return_dict is `True`,\n                [`~schedulers.scheduling_flow_match_euler_discrete.FlowMatchEulerDiscreteSchedulerOutput`] is returned,\n                otherwise a tuple is returned where the first element is the sample tensor.\n        \"\"\"\n\n        if isinstance(timestep, int | torch.IntTensor | torch.LongTensor):\n            raise ValueError(\n                (\n                    \"Passing integer indices (e.g. from `enumerate(timesteps)`) as timesteps to\"\n                    \" `FlowMatchEulerDiscreteScheduler.step()` is not supported. Make sure to pass\"\n                    \" one of the `scheduler.timesteps` as a timestep.\"\n                ),\n            )\n\n        if self.step_index is None:\n            self._init_step_index(timestep)\n\n        # Upcast to avoid precision issues when computing prev_sample\n        sample = sample.to(torch.float32)\n\n        if per_token_timesteps is not None:\n            per_token_sigmas = per_token_timesteps / self.config.num_train_timesteps\n\n            sigmas = self.sigmas[:, None, None]\n            lower_mask = sigmas < per_token_sigmas[None] - 1e-6","sourceCodeStart":474,"sourceCodeEnd":510,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/schedulers/scheduling_flow_match_euler_discrete.py#L474-L510","documentation":"step() rejects int / IntTensor / LongTensor timesteps because flow-match timesteps are continuous floats; integer values are ambiguous with loop indices and would break _init_step_index's searchsorted lookup.","triggerScenarios":"`for i, t in enumerate(scheduler.timesteps): scheduler.step(..., i, ...)`; passing numpy int64 t; casting timesteps with int() for logging then reusing them.","commonSituations":"The classic enumerate-index bug ported across diffusion codebases; timesteps arrays saved/loaded through integer numpy pipelines.","solutions":["Pass the loop's t value (float), not the index","Cast with float(t) or t.astype(np.float32) when timesteps come from numpy int arrays","Use zip/tqdm over timesteps directly"],"exampleFix":"# before\nfor i, t in enumerate(scheduler.timesteps):\n    sample = scheduler.step(model_output, i, sample).prev_sample\n# after\nfor t in scheduler.timesteps:\n    sample = scheduler.step(model_output, t, sample).prev_sample","handlingStrategy":"type-guard","validationCode":"for t in scheduler.timesteps:\n    t = float(t)\n    scheduler.step(model_output, t, sample)","typeGuard":"def float_timestep(t):\n    if isinstance(t, (int, np.integer, torch.IntTensor, torch.LongTensor)):\n        return float(t)\n    return t","tryCatchPattern":null,"preventionTips":["Never pass enumerate indices as timesteps","Cast numpy int schedules to float32 once at load time"],"tags":["scheduler","timestep-type","flow-matching"],"backgroundTag":"invalid-timestep-type","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}