{"id":50980567,"url":"https://github.com/louieworth/trd","last_synced_at":"2026-07-07T11:00:31.393Z","repository":{"id":363475409,"uuid":"1260931078","full_name":"louieworth/trd","owner":"louieworth","description":"Official Implementation of Trajectory-Refined Distillation","archived":false,"fork":false,"pushed_at":"2026-06-09T04:12:01.000Z","size":1622,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-09T05:13:31.630Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/louieworth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":"Notice.txt","maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-06T03:24:04.000Z","updated_at":"2026-06-09T04:12:06.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/louieworth/trd","commit_stats":null,"previous_names":["louieworth/trd"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/louieworth/trd","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/louieworth%2Ftrd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/louieworth%2Ftrd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/louieworth%2Ftrd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/louieworth%2Ftrd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/louieworth","download_url":"https://codeload.github.com/louieworth/trd/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/louieworth%2Ftrd/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35225029,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-07T02:00:07.222Z","response_time":90,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-19T14:00:18.565Z","updated_at":"2026-07-07T11:00:31.380Z","avatar_url":"https://github.com/louieworth.png","language":"Python","funding_links":[],"categories":["🔬 OPD with Larger External Teachers — White-Box"],"sub_categories":[],"readme":"# Trajectory-Refined Distillation\n\n[![ArXiv](https://img.shields.io/badge/arXiv-2606.08432-b31b1b.svg)](https://arxiv.org/abs/2606.08432)\n[![HuggingFace](https://img.shields.io/badge/%F0%9F%A4%97%20HuggingFace-2606.08432-yellow.svg)](https://huggingface.co/papers/2606.08432)\n[![License](https://img.shields.io/badge/License-Apache--2.0-blue.svg)](LICENSE)\n\n**Authors:** Li Jiang, Haoran Xu, Yichuan Ding, Amy Zhang\n\nTrajectory-Refined Distillation (TRD) addresses prefix failure in on-policy distillation by revising student rollouts $y_o$ under teacher guidance before KL training. It moves beyond token-level loss interventions to trajectory-level output refinement resulting the TRD refined target $y_r$ (ours), and can be applied to both OPD and OPSD training. This repository provides the cleaned TRD training code, task wrappers, and math/code evaluation recipes needed to reproduce KL training on top of `verl`.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"scripts/trd.jpg\" alt=\"Trajectory-Refined Distillation algorithm overview\" width=\"90%\"\u003e\n\u003c/p\u003e\n\n## What Is Included\n\n- `recipe/opd/`: OPD/OPSD trainer, KL losses, data preparation, rollout preparation, and run wrappers.\n- `recipe/opd/run/run_kl_training.sh`: training entrypoint.\n- `recipe/opd/run/opd/{code,math}/$MODEL/*.sh`: OPD wrappers.\n- `recipe/opd/run/opsd/{code,math}/$MODEL/*.sh`: OPSD wrappers.\n- `recipe/math_evaluation/`: math benchmark runner and dataset preparation utilities.\n- `recipe/code_evaluation/`: code benchmark runner, EvalPlus/LiveCodeBench helpers, and local LiveCodeBench copy.\n- `verl/`: the underlying training/generation runtime used by the OPD recipe.\n\n## Environment\n\nFollow the official [verl installation guide](https://verl.readthedocs.io/en/latest/start/install.html) for the CUDA, PyTorch, Ray, vLLM, Transformers, and other runtime dependencies. After the `verl` environment is ready, install this repository in editable mode:\n\n```bash\npip install -e .\n```\n\nFor code evaluation, also install EvalPlus and the bundled LiveCodeBench runner:\n\n```bash\npython -m pip install --upgrade \"evalplus[vllm] @ git+https://github.com/evalplus/evalplus\"\npython -m pip install -e recipe/code_evaluation/external/LiveCodeBench\nexport LCB_REPO=$PWD/recipe/code_evaluation/external/LiveCodeBench\n```\n\n## Dataset Preparation\n\nSet the local data root once, then prepare the fixed training and evaluation datasets with the provided scripts.\n\n```bash\nexport DATA_ROOT=$PWD/data\nexport TRAIN_DATA_PATH=$DATA_ROOT/train/DeepScaleR      # math training\nexport CODE_TRAIN_DATA_PATH=$DATA_ROOT/train/TACO       # code training\nexport EVAL_DATASETS_DIR=$DATA_ROOT/eval\n\nmkdir -p \"$DATA_ROOT/train\" \"$EVAL_DATASETS_DIR\"\n\n# Math training dataset: agentica-org/DeepScaleR-Preview-Dataset\npython recipe/opd/dataset/prepare_deepscaler.py \\\n  --output_dir \"$TRAIN_DATA_PATH\"\n\n# Code training dataset: BAAI/TACO\npython recipe/opd/dataset/prepare_taco.py \\\n  --output_dir \"$CODE_TRAIN_DATA_PATH\"\n\n# Math evaluation datasets\npython recipe/math_evaluation/datasets/prepare_aime.py \\\n  --local_save_dir \"$EVAL_DATASETS_DIR\"\npython recipe/math_evaluation/datasets/prepare_hmmt.py \\\n  --local_dataset_path \"$EVAL_DATASETS_DIR\"\npython recipe/math_evaluation/datasets/prepare_additional_eval_datasets.py \\\n  --datasets beyondaime,amobench \\\n  --local_save_dir \"$EVAL_DATASETS_DIR\"\n```\n\nFor code wrappers, set `TRAIN_DATA_PATH=$CODE_TRAIN_DATA_PATH` before launching.\n\n## Run Training\n\nEach wrapper sets the task, model family, KL variant, y-mode, and length budgets, then calls `recipe/opd/run/run_kl_training.sh`.\n\nExamples:\n\n```bash\nexport DATA_ROOT=$PWD/data\nexport EVAL_DATASETS_DIR=$DATA_ROOT/eval\n\n# OPD code, Qwen3-1.7B, reverse KL + top-k\nexport TRAIN_DATA_PATH=$DATA_ROOT/train/TACO\nbash recipe/opd/run/opd/code/qwen3-1.7B/reverse_kl_topk.sh\n\n# OPD math, Qwen3-4B-Instruct, forward KL on TRD refined target y_r (ours)\nexport TRAIN_DATA_PATH=$DATA_ROOT/train/DeepScaleR\nbash recipe/opd/run/opd/math/qwen3-4b-instruct/forward_kl_y_r.sh\n\n# OPSD math, teacher equals student\nexport TRAIN_DATA_PATH=$DATA_ROOT/train/DeepScaleR\nbash recipe/opd/run/opsd/math/qwen3-1.7B/forward_kl_clip.sh\n```\n\nAvailable variants under every model directory:\n\n- `forward_kl.sh`: forward KL on `y_o`.\n- `forward_kl_y_r.sh`: forward KL on the TRD refined target `y_r` (ours).\n- `forward_kl_clip.sh`: forward KL on `y_o` with token-level KL clipping.\n- `reverse_kl.sh`: reverse KL on `y_o`.\n- `reverse_kl_topk.sh`: reverse KL on `y_o` with teacher top-k support.\n\n## Evaluation\n\nTraining wrappers can run final evaluation automatically with `RUN_EVAL_AFTER_TRAINING=true` (default). To skip evaluation:\n\n```bash\nexport RUN_EVAL_AFTER_TRAINING=false\n```\n\nTo evaluate an existing model manually:\n\n```bash\nexport DATA_ROOT=$PWD/data\n\n# Math\nEVAL_DATASETS_DIR=$DATA_ROOT/eval \\\nDATASETS=\"aime24,aime25,hmmt25,beyondaime,amobench\" \\\nbash recipe/math_evaluation/benchmark_kl_model.sh /path/to/hf_merged\n\n# Code\nDATASETS=\"humaneval_plus,mbpp_plus,livecodebench_v6\" \\\nbash recipe/code_evaluation/benchmark_code_model.sh /path/to/hf_merged\n```\n\n## Citation\n\nIf you find this work useful, please cite:\n\n```bibtex\n@article{jiang2026trajectory,\n  title={Trajectory-Refined Distillation},\n  author={Jiang, Li and Xu, Haoran and Ding, Yichuan and Zhang, Amy},\n  journal={arXiv preprint},\n  year={2026},\n  note={Coming soon}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flouieworth%2Ftrd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flouieworth%2Ftrd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flouieworth%2Ftrd/lists"}