Add token export visualizer#2551
Draft
samsja wants to merge 6 commits into
Draft
Conversation
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 eebc96e. Configure here.
497270a to
95057dc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
src/prime_rl/trainer/rl/token_export.py, and exporter-specific ratio/mask math is scoped there instead of inline in the trainer loop.*.jsonlexports into one static HTML page, and single JSONL files can use--all-recordsto embed every matching record.Verification
uv run ruff check packages/prime-rl-configs/src/prime_rl/configs/trainer.py src/prime_rl/transport/types.py src/prime_rl/trainer/batch.py src/prime_rl/trainer/rl/data.py src/prime_rl/trainer/rl/train.py src/prime_rl/trainer/rl/token_export.py scripts/token_export_visualizer.pyuv run ruff check src/prime_rl/trainer/rl/train.py src/prime_rl/trainer/rl/token_export.py scripts/token_export_visualizer.pyuv run ruff format --check src/prime_rl/trainer/rl/train.py src/prime_rl/trainer/rl/token_export.py scripts/token_export_visualizer.pyuv run ruff check packages/prime-rl-configs/src/prime_rl/configs/trainer.py src/prime_rl/trainer/rl/token_export.pyuv run ruff format --check packages/prime-rl-configs/src/prime_rl/configs/trainer.py src/prime_rl/trainer/rl/token_export.pyuv run python -m py_compile src/prime_rl/trainer/rl/token_export.py packages/prime-rl-configs/src/prime_rl/configs/trainer.pyuv run ruff check scripts/token_export_visualizer.pyuv run ruff format --check scripts/token_export_visualizer.pyuv run rl @ configs/ci/integration/reverse_text/start.toml --output-dir /tmp/prime-rl-token-export-clean-run --clean-output-dir --max-steps 1 --seq-len 512 --orchestrator.batch-size 2 --orchestrator.rollouts-per-example 2 --orchestrator.train.sampling.max-completion-tokens 16 --trainer.experimental.token-exportuv run scripts/token_export_visualizer.py /tmp/prime-rl-token-export-clean-run/token_exports --tokenizer PrimeIntellect/Qwen3-0.6B-Reverse-Text-SFT -o output.htmluv run scripts/token_export_visualizer.py /tmp/prime-rl-token-export-clean-run/token_exports --tokenizer PrimeIntellect/Qwen3-0.6B-Reverse-Text-SFT -o /tmp/prime-rl-token-export-clean-run/output.html/tmp/prime-rl-token-export-clean-run/token_exports/rank_0.jsonlhas 2 records and nois_clippedfield.No pytest tests were added or run, per request.
Note
Medium Risk
Touches the RL training loop and batch serialization by adding a new
rewardsfield and export hook; while gated behindexperimental.token_export, incorrect alignment/IO failures could impact training stability or performance when enabled.Overview
Adds opt-in per-token rollout export for the RL trainer via
trainer.experimental.token_export, writing per-sequence JSONL records (token ids plus aligned metrics like reward/advantage/entropy, mismatch KL, importance ratios, and DPPO mask diagnostics) using an async writer (trainer/rl/token_export.py).Threads
rewardsthrough the trainer data path (TrainingSample->MicroBatch->TensorMicroBatch), updates packing/padding logic to keep reward arrays aligned, and hooks exporter setup/export/close intotrainer/rl/train.py.Introduces
scripts/token_export_visualizer.py, a standalone CLI that loads JSONL (file or directory), optionally decodes tokens with a tokenizer, and renders a static navigable HTML view with KL-based highlighting and hoverable token details; documents the workflow inskills/config/SKILL.md.Reviewed by Cursor Bugbot for commit eebc96e. Bugbot is set up for automated code reviews on this repo. Configure here.