Repository navigation
perf: encode json with orjson - #4266
mikasenghaas wants to merge 1 commit into
Conversation
Resolved configs, metric rows, log lines, weight indices and test fixtures now go through orjson. The indented files keep the stdlib layout; non-ASCII text is written as UTF-8 instead of \u escapes. Two scripts keep the stdlib: scripts/docker_dependencies.py and tests/regression/scripts/eval.py run without the project venv. The episode-record test keeps it because it checks the SDK's stdlib encoder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 5499284. Configure here.
| if self.producer is not None: | ||
| row["producer"] = self.producer | ||
| self.file.write(json.dumps(row) + "\n") | ||
| self.file.write(orjson.dumps(row).decode() + "\n") |
There was a problem hiding this comment.
orjson rejects numpy metric scalars
Medium Severity
log_metrics now encodes each row with orjson.dumps and no OPT_SERIALIZE_NUMPY. sanitize keeps finite numpy.float64 / numpy.int64 values (they pass the float/int checks), and orjson then raises TypeError on those types. json.dumps accepted them because those numpy scalars subclass the builtins. The same monitor already uses OPT_SERIALIZE_NUMPY for traces, so a numpy scalar in a metric row can fail the write and abort the logging call.
Reviewed by Cursor Bugbot for commit 5499284. Configure here.
|
Closing: orjson only pays off on the episode serialization path, where records are large. Entrypoints, logging, weights and the other small payloads stay on the stdlib |


Summary
srcand the unit tests:WANDB_ARGS, eval--source, the vLLM override fragment, tool-call and tool-schema parsing in SFT datascripts/docker_dependencies.pyandtests/regression/scripts/eval.py, which run without the project venvtests/unit/orchestrator/test_episode_records.py, which checks the prime SDK's stdlib encoderpackages/prime-rl-configsunchanged. It does not depend on orjson.Output changes: non-ASCII text is UTF-8 instead of
\uXXXXescapes.WANDB_ARGSand the vLLM override fragment are compact. Every consumer parses the JSON.Related: PrimeIntellect-ai/prime#1109 moves the prime SDK to orjson, and PrimeIntellect-ai/verifiers#2981 does the same for verifiers.
Verification
tests/unit(CPU box): 718 passed.reverse_text/gsm8kenv packages, no NVIDIA driver, or noprime_kernels.DID NOT WARNconfig tests fail onmainas well.test_weights.pyneedsprime_kernelsand could not run. The index encoding matchesjson.dumps(indent=2, sort_keys=True)byte for byte on a sample index.🤖 Generated with Claude Code
Note
Medium Risk
Wide mechanical swap across config persistence, logging, and W&B argv round-trips; format differences are documented but any missed consumer assuming stdlib JSON escaping could break edge cases.
Overview
Replaces the stdlib
jsonmodule withorjsonacross launchers, utilities, monitors, inference logging, trainer code, and unit tests.Serialization paths now use
orjson.loads/dumpswithread_bytes/write_byteswhere appropriate: resolved run configs (RL, SFT, eval, inference, env-server JSON), dashboard registry files, safetensors index files (still indented + sorted keys), metrics JSONL rows, loguru and vLLM JSON log lines, and the temp vLLMdictConfigfile.CLI and env wiring changes include eval
--sourceshorthands andWANDB_ARGS(compact JSON,.decode()for strings), plus vLLM override fragments embedded in SLURM/bash strings. SFT/tool-call parsing and JSON-encoded tool schemas useorjson.loadsas well.Intentional exceptions (per description): stdlib
jsonremains in a few scripts/tests outside the main venv path;prime-rl-configsis untouched.Output differences: non-ASCII text is written as UTF-8 instead of
\uescapes; some embedded JSON is compact rather than pretty-printed. Call sites that need human-readable files keeporjson.OPT_INDENT_2.Reviewed by Cursor Bugbot for commit 5499284. Bugbot is set up for automated code reviews on this repo. Configure here.