{"record":{"id":"66fe3d715459a6ed","repo":"sgl-project/sglang","slug":"generator-must-be-provided","errorCode":null,"errorMessage":"Generator must be provided","messagePattern":"Generator must be provided","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/stages/image_encoding.py","lineNumber":971,"sourceCode":"                    should_cast_vae = not vae_autocast_enabled\n                    if not vae_autocast_enabled:\n                        video_condition = video_condition.to(vae_dtype)\n                    video_condition = server_args.pipeline_config.preprocess_vae_encode(\n                        video_condition, self.vae\n                    )\n                    with temporary_module_dtype(\n                        self.vae, vae_dtype, enabled=should_cast_vae\n                    ) as vae:\n                        latent_dist: DiagonalGaussianDistribution = vae.encode(\n                            video_condition\n                        )\n                    # for auto_encoder from diffusers\n                    if isinstance(latent_dist, AutoencoderKLOutput):\n                        latent_dist = latent_dist.latent_dist\n\n                generator = batch.generator\n                if generator is None:\n                    raise ValueError(\"Generator must be provided\")\n\n                sample_mode = (\n                    server_args.pipeline_config.vae_config.encode_sample_mode()\n                )\n\n                latent_condition = self.retrieve_latents(\n                    latent_dist, generator, sample_mode=sample_mode\n                )\n                latent_condition = server_args.pipeline_config.postprocess_vae_encode(\n                    latent_condition, self.vae\n                )\n                normalized_latent_condition = (\n                    server_args.pipeline_config.normalize_vae_encode(\n                        latent_condition, self.vae\n                    )\n                )\n                if normalized_latent_condition is None:\n                    scaling_factor, shift_factor = (","sourceCodeStart":953,"sourceCodeEnd":989,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/image_encoding.py#L953-L989","documentation":"In the image-encoding stage's VAE latent sampling path, the per-batch random generator (batch.generator) is required to sample latents from the encoded distribution deterministically. If the batch was constructed without a torch.Generator (generator=None), the stage refuses to sample because reproducibility would be lost and downstream code assumes a per-request generator exists.","triggerScenarios":"Building a request/batch object manually without setting generator, or a server path that only sets a global seed and forgets to attach a per-batch torch.Generator before reaching image encoding with vae_config.encode_sample_mode() requiring sampling.","commonSituations":"Calling the pipeline programmatically with a custom Batch dataclass; refactoring that dropped generator propagation; requests that set seed=0/None and a code path that then leaves batch.generator unset; version changes that made the generator mandatory for VAE sampling.","solutions":["Set batch.generator = torch.Generator(device=...).manual_seed(seed) before submitting the request","If your server args accept a seed, verify the seed-handling path populates batch.generator rather than only a global seed","When constructing batches manually, mirror how the standard request path creates generators (device-matched, seeded per prompt)"],"exampleFix":"// before\nbatch = ImageBatch(images=imgs)  # generator missing\n\n// after\ngen = torch.Generator(device=latents_device).manual_seed(seed)\nbatch = ImageBatch(images=imgs, generator=gen)","handlingStrategy":"validation","validationCode":"if batch.generator is None:\n    batch.generator = torch.Generator(device=device).manual_seed(seed or 0)","typeGuard":"def has_generator(batch) -> bool:\n    return getattr(batch, \"generator\", None) is not None","tryCatchPattern":null,"preventionTips":["Always construct a seeded per-batch torch.Generator when building requests programmatically","Use the standard request path so generators are attached automatically","Device-match the generator to the latent device"],"tags":["generator","vae-sampling","determinism","batch-construction"],"backgroundTag":"missing-random-generator","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}