sgl-project/sglang · error · ValueError
--diffusers-kwargs must be valid JSON. Got: {args.diffusers_
Error message
--diffusers-kwargs must be valid JSON. Got: {args.diffusers_kwargs} What it means
Raised by the `generate` CLI command when --diffusers-kwargs is provided but is not parseable as JSON (json.JSONDecodeError). The string is json.loads-ed into sampling_params_kwargs['diffusers_kwargs']; any syntax error (trailing commas, single quotes, unquoted keys) aborts command startup.
Source
Thrown at python/sglang/multimodal_gen/runtime/entrypoints/cli/generate.py:195
sampling_params_kwargs.update(sampling_params_cls.get_cli_args(args))
_apply_output_file_path_override(args, sampling_params_kwargs)
sampling_params_kwargs["request_id"] = generate_request_id()
if sampling_params_kwargs.get("use_diffusion_decoder", False):
server_args.load_diffusion_decoder = True
# Handle diffusers-specific kwargs passed via CLI
if hasattr(args, "diffusers_kwargs") and args.diffusers_kwargs:
try:
sampling_params_kwargs["diffusers_kwargs"] = json.loads(
args.diffusers_kwargs
)
logger.info(
"Parsed diffusers_kwargs: %s",
sampling_params_kwargs["diffusers_kwargs"],
)
except json.JSONDecodeError as e:
logger.error("Failed to parse --diffusers-kwargs as JSON: %s", e)
raise ValueError(
f"--diffusers-kwargs must be valid JSON. Got: {args.diffusers_kwargs}"
) from e
generator = DiffGenerator.from_pretrained(
model_path=server_args.model_path, server_args=server_args, local_mode=True
)
results = generator.generate(sampling_params_kwargs=sampling_params_kwargs)
prompt = sampling_params_kwargs.get("prompt")
maybe_dump_performance(args, server_args, prompt, results)
class GenerateSubcommand(CLISubcommand):
"""The `generate` subcommand for the sglang-diffusion CLI"""
def __init__(self) -> None:
self.name = "generate"View on GitHub (pinned to 0132848349)
Solutions
- Rewrite the argument as strict JSON: double quotes on keys and string values, no trailing commas
- Echo or dry-run print the argument to check shell quoting didn't mangle it
- Validate with `python -c "import json,sys; json.loads(sys.argv[1])" '<your string>'` before running the command
Example fix
# before
--diffusers-kwargs "{'num_inference_steps': 20,}"
# after
--diffusers-kwargs '{"num_inference_steps": 20}' Defensive patterns
Strategy: validation
Validate before calling
import json json.loads(args.diffusers_kwargs) # fails fast with a clear JSONDecodeError
Prevention
- Always write CLI JSON kwargs with double quotes and no trailing commas
- Validate the string with json.loads in CI/scripts before invoking the CLI
- Beware shell quoting: prefer single-quoting the whole JSON blob
When it happens
Trigger: Running `sglang generate ... --diffusers-kwargs '{num_inference_steps: 20}'` or with single-quoted values / trailing commas — anything json.loads rejects.
Common situations: Copy-pasting Python-dict-style kwargs (single quotes, bare keys) from code or docs into the CLI; shell quoting issues that truncate the JSON; missing closing brace.
Related errors
- Number of gpus must be positive
- Config file not found: {args.config}
- Config file not found: {args.config}
- error: unrecognized arguments: {' '.join(remaining)}
- Invalid JSON mapping: {normalized_input}
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/63789601d053a829.
Report an issue: GitHub.