google-tunix 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. google_tunix-0.0.1.dist-info/METADATA +155 -0
  2. google_tunix-0.0.1.dist-info/RECORD +85 -0
  3. google_tunix-0.0.1.dist-info/WHEEL +5 -0
  4. google_tunix-0.0.1.dist-info/licenses/LICENSE +202 -0
  5. google_tunix-0.0.1.dist-info/top_level.txt +1 -0
  6. tunix/__init__.py +28 -0
  7. tunix/distillation/__init__.py +20 -0
  8. tunix/distillation/distillation_trainer.py +136 -0
  9. tunix/distillation/feature_extraction/__init__.py +25 -0
  10. tunix/distillation/feature_extraction/pooling.py +130 -0
  11. tunix/distillation/feature_extraction/projection.py +140 -0
  12. tunix/distillation/feature_extraction/sowed_module.py +182 -0
  13. tunix/distillation/strategies/__init__.py +24 -0
  14. tunix/distillation/strategies/attention.py +114 -0
  15. tunix/distillation/strategies/base_strategy.py +152 -0
  16. tunix/distillation/strategies/feature_pooling.py +198 -0
  17. tunix/distillation/strategies/feature_projection.py +197 -0
  18. tunix/distillation/strategies/logit.py +123 -0
  19. tunix/examples/data/translation_dataset.py +293 -0
  20. tunix/generate/base_sampler.py +77 -0
  21. tunix/generate/beam_search.py +275 -0
  22. tunix/generate/sampler.py +796 -0
  23. tunix/generate/tokenizer_adapter.py +124 -0
  24. tunix/generate/utils.py +587 -0
  25. tunix/generate/vllm_sampler.py +300 -0
  26. tunix/models/gemma/gemma.py +968 -0
  27. tunix/models/gemma/params.py +84 -0
  28. tunix/models/gemma/params_safetensors.py +186 -0
  29. tunix/models/gemma/sampler.py +690 -0
  30. tunix/models/gemma3/model.py +822 -0
  31. tunix/models/gemma3/params.py +139 -0
  32. tunix/models/gemma3/params_safetensors.py +208 -0
  33. tunix/models/llama3/model.py +796 -0
  34. tunix/models/llama3/params.py +95 -0
  35. tunix/models/qwen2/model.py +772 -0
  36. tunix/models/qwen2/params.py +99 -0
  37. tunix/models/qwen3/model.py +703 -0
  38. tunix/models/qwen3/params.py +127 -0
  39. tunix/models/safetensors_loader.py +162 -0
  40. tunix/oss/utils.py +27 -0
  41. tunix/rl/common.py +331 -0
  42. tunix/rl/experimental/agentic/agents/agent_types.py +94 -0
  43. tunix/rl/experimental/agentic/agents/base_agent.py +198 -0
  44. tunix/rl/experimental/agentic/agents/tool_agent.py +251 -0
  45. tunix/rl/experimental/agentic/environments/base_environment.py +153 -0
  46. tunix/rl/experimental/agentic/environments/tool_environment.py +230 -0
  47. tunix/rl/experimental/agentic/parser/tool_parser/gemini_parser.py +24 -0
  48. tunix/rl/experimental/agentic/parser/tool_parser/qwen_parser.py +110 -0
  49. tunix/rl/experimental/agentic/parser/tool_parser/tool_parser_base.py +96 -0
  50. tunix/rl/experimental/agentic/parser/tool_parser/tool_parser_registry.py +16 -0
  51. tunix/rl/experimental/agentic/prompts/prompt_template.py +26 -0
  52. tunix/rl/experimental/agentic/rewards/reward.py +152 -0
  53. tunix/rl/experimental/agentic/rewards/reward_types.py +51 -0
  54. tunix/rl/experimental/agentic/tools/base_tool.py +210 -0
  55. tunix/rl/experimental/agentic/tools/calculator_tool.py +99 -0
  56. tunix/rl/experimental/agentic/tools/tool_manager.py +179 -0
  57. tunix/rl/experimental/agentic/trajectory/trajectory_collect_engine.py +226 -0
  58. tunix/rl/grpo/grpo_helpers.py +34 -0
  59. tunix/rl/grpo/grpo_learner.py +450 -0
  60. tunix/rl/inference/inference_worker.py +94 -0
  61. tunix/rl/ppo/ppo_helpers.py +145 -0
  62. tunix/rl/ppo/ppo_learner.py +549 -0
  63. tunix/rl/queue/data_queue.py +65 -0
  64. tunix/rl/reshard.py +211 -0
  65. tunix/rl/rl_cluster.py +763 -0
  66. tunix/rl/rl_learner.py +611 -0
  67. tunix/rl/rollout/base_rollout.py +129 -0
  68. tunix/rl/rollout/vanilla_rollout.py +115 -0
  69. tunix/rl/rollout/vllm_rollout.py +113 -0
  70. tunix/rl/trainer.py +94 -0
  71. tunix/rl/utils.py +312 -0
  72. tunix/sft/checkpoint_manager.py +143 -0
  73. tunix/sft/config.py +388 -0
  74. tunix/sft/dpo/dpo_trainer.py +454 -0
  75. tunix/sft/hooks.py +76 -0
  76. tunix/sft/inflight_throttler.py +66 -0
  77. tunix/sft/metrics_logger.py +197 -0
  78. tunix/sft/peft_main.py +410 -0
  79. tunix/sft/peft_trainer.py +799 -0
  80. tunix/sft/profiler.py +91 -0
  81. tunix/sft/progress_bar.py +90 -0
  82. tunix/sft/sharding_utils.py +41 -0
  83. tunix/sft/system_metrics_calculator.py +75 -0
  84. tunix/sft/utils.py +39 -0
  85. tunix/tests/test_common.py +238 -0
@@ -0,0 +1,155 @@
1
+ Metadata-Version: 2.4
2
+ Name: google-tunix
3
+ Version: 0.0.1
4
+ Summary: A lightweight JAX-native LLM post-training framework.
5
+ Author-email: Tunix Developers <tunix-dev@google.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Source, https://github.com/google/tunix
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
13
+ Requires-Python: >=3.12
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: datasets
17
+ Requires-Dist: flax
18
+ Requires-Dist: grain
19
+ Requires-Dist: huggingface_hub
20
+ Requires-Dist: jax
21
+ Requires-Dist: jax[tpu]
22
+ Requires-Dist: jaxtyping
23
+ Requires-Dist: kagglehub
24
+ Requires-Dist: omegaconf
25
+ Requires-Dist: qwix
26
+ Requires-Dist: sentencepiece
27
+ Requires-Dist: tensorboardX
28
+ Requires-Dist: tensorflow_datasets
29
+ Requires-Dist: tqdm
30
+ Requires-Dist: transformers
31
+ Provides-Extra: docs
32
+ Requires-Dist: sphinx>=8.2.3; extra == "docs"
33
+ Requires-Dist: sphinx-book-theme>=1.1.4; extra == "docs"
34
+ Requires-Dist: sphinx-autodoc-typehints; extra == "docs"
35
+ Requires-Dist: ipython>=8.8.0; extra == "docs"
36
+ Requires-Dist: myst-nb>=1.3.0; extra == "docs"
37
+ Requires-Dist: matplotlib>=3.10.0; extra == "docs"
38
+ Requires-Dist: sphinx-gallery>=0.19.0; extra == "docs"
39
+ Requires-Dist: sphinx-collections>=0.0.1; extra == "docs"
40
+ Requires-Dist: sphinx_contributors; extra == "docs"
41
+ Dynamic: license-file
42
+
43
+ # Tunix: A JAX-native LLM Post-Training Library
44
+
45
+ **Tunix(Tune-in-JAX)** is a JAX based library designed to streamline the
46
+ post-training of Large Language Models. It provides efficient and scalable
47
+ supports for:
48
+
49
+ - **Supervised Fine-Tuning**
50
+ - **Reinforcement Learning (RL)**
51
+ - **Knowledge Distillation**
52
+
53
+ Tunix leverages the power of JAX for accelerated computation and seamless
54
+ integration with JAX-based modeling framework
55
+ [Flax NNX](https://flax.readthedocs.io/en/latest/nnx_basics.html).
56
+
57
+ **Current Status: Early Development**
58
+
59
+ Tunix is in early development. We're actively working to expand its
60
+ capabilities, usability and improve its performance. Stay tuned for upcoming
61
+ updates and new features!
62
+
63
+ ## Key Features & Highlights
64
+
65
+ Tunix is still under development, here's a glimpse of the current features:
66
+
67
+ - **Supervised Fine-Tuning:**
68
+ - Full Weights Fine-Tuning
69
+ - Parameter-Efficient Fine-Tuning (PEFT) with LoRA/Q-LoRA Layers
70
+ - **Reinforcement Learning (RL):**
71
+ - Proximal Policy Optimization (PPO)
72
+ - Group Relative Policy Optimization (GRPO)
73
+ - Token-level Group Sequence Policy Optimization (GSPO-token)
74
+ - **Preference Fine-Tuning:**
75
+ - Preference alignments with Direct Preference Optimization (DPO)
76
+ - **Knowledge Distillation:**
77
+ - Logit Strategy: A classic approach where the student learns to match the
78
+ teacher's output probability distribution.
79
+ - Attention Transfer & Projection Strategies: Methods to align the attention
80
+ mechanisms between the student and teacher models.
81
+ - Feature Pooling & Projection Strategies: General techniques for matching
82
+ intermediate feature representations, even between models of different
83
+ architectures.
84
+ - **Modularity:**
85
+ - Components are designed to be reusable and composable
86
+ - Easy to customize and extend
87
+ - **Efficiency:**
88
+ - Native support of common model sharding strategies such as DP, FSDP and TP
89
+ - Designed for distributed training on accelerators (TPU)
90
+
91
+ ## Upcoming
92
+
93
+ - **Agentic RL Training:**
94
+ - Async Rollout
95
+ - Multi-turn & multi-step support
96
+ - Tool usage
97
+ - **Advanced Algorithms:**
98
+ - Addtional state-of-the-art RL and distillation algorithms
99
+ - **Scalability:**
100
+ - Multi-host distributed training
101
+ - Optimized rollout with vLLM
102
+ - **User Guides:**
103
+ - More advanced RL recipe
104
+
105
+ ## Installation
106
+
107
+ Tunix doesn't have a PyPI package yet. To use Tunix, you need to install from
108
+ GitHub directly.
109
+
110
+ ```sh
111
+ pip install git+https://github.com/google/tunix
112
+ ```
113
+
114
+ ## Getting Started
115
+
116
+ To get started, we have a bunch of detailed examples and tutorials.
117
+
118
+ - [PEFT Gemma with QLoRA](https://github.com/google/tunix/blob/main/examples/qlora_demo.ipynb)
119
+ - [Training Gemma on grade school Math problems using GRPO](https://github.com/google/tunix/blob/main/examples/grpo_demo.ipynb)
120
+ - [Logit Distillation using Gemma models](https://github.com/google/tunix/blob/main/examples/logit_distillation.ipynb)
121
+
122
+ To setup Jupyter notebook on single host GCP TPU VM, please refer to the
123
+ [setup script](https://github.com/google/tunix/blob/main/scripts/setup_notebook_tpu_single_host.sh).
124
+
125
+ We plan to provide clear, concise documentation and more examples in the near
126
+ future.
127
+
128
+ ## Contributing and Feedbacks
129
+
130
+ We welcome contributions! As Tunix is in early development, the contribution
131
+ process is still being formalized. A rough draft of the contribution process is
132
+ present [here](https://github.com/google/tunix/blob/main/CONTRIBUTING.md). In
133
+ the meantime, you can make feature requests, report issues and ask questions in
134
+ our
135
+ [Tunix GitHub discussion forum](https://github.com/google/tunix/discussions).
136
+
137
+ ## Collaborations and Partnership
138
+
139
+ [GRL](https://github.com/lmgame-org/GRL/blob/tunix_integration_dev/README.md)
140
+ (Game Reinforcement Learning), developed by
141
+ [Hao AI Lab](https://hao-ai-lab.github.io/) from UCSD, is an open-source
142
+ framework for post-training large language models through multi-turn RL on
143
+ challenging games. In collaboration with Tunix, GRL integrates seamless TPU
144
+ support—letting users quickly run scalable, reproducible RL experiments (like
145
+ PPO rollouts on Qwen2.5-0.5B-Instruct) on TPU v4 meshes with
146
+ [minimal setup](https://github.com/lmgame-org/GRL/blob/tunix_integration_dev/README.md#5-launch-the-quick-test-defaults-to-qwen2505b-supports-4-tpu-v4-with-mesh-22).
147
+ This partnership empowers the community to push LLM capabilities further,
148
+ combining Tunix’s optimized TPU runtime with GRL’s flexible game RL pipeline for
149
+ cutting-edge research and easy reproducibility.
150
+
151
+ ## Stay Tuned!
152
+
153
+ Thank you for your interest in Tunix. We're working hard to bring you a powerful
154
+ and efficient library for LLM post-training. Please follow our progress and
155
+ check back for updates!
@@ -0,0 +1,85 @@
1
+ google_tunix-0.0.1.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
2
+ tunix/__init__.py,sha256=I_aCYRv7VOXgsrQ30fZVE36913XQBR-bRtMOY33fhsk,1295
3
+ tunix/distillation/__init__.py,sha256=IZXRKcxXQlmirRKz3RMD_VkAjQIW5tG55vgIem498WM,869
4
+ tunix/distillation/distillation_trainer.py,sha256=eQV3b500_TwFlyy1l4F9AzFn80NyNxIFW3RLpFCfAuc,4205
5
+ tunix/distillation/feature_extraction/__init__.py,sha256=5ule3xq3xUjYqDVMzAfbE833Ibg3mUDpzAykHAnZuTY,1386
6
+ tunix/distillation/feature_extraction/pooling.py,sha256=PRRDyQ3OmzUP0PnxAgWvW5hEvTZz8QmIlaxQi-lLLmQ,4661
7
+ tunix/distillation/feature_extraction/projection.py,sha256=NietUThUfij3UcHW-oS-zkLHvtguBlDXDnSmQOiyf0k,4853
8
+ tunix/distillation/feature_extraction/sowed_module.py,sha256=B66GzK7Me07iObLyA9ToOFj2J9Q0XngWyMdchoxTCiE,6210
9
+ tunix/distillation/strategies/__init__.py,sha256=C-NHVX7IBAsvbkb37YFU4dJMYVuDYoERMcv7oRlqrC0,1200
10
+ tunix/distillation/strategies/attention.py,sha256=7z9DYzkP-OSpJCDwkZuAKr8_m2oV02VQJE8mmi-i54Y,4272
11
+ tunix/distillation/strategies/base_strategy.py,sha256=gIT-2DgTf-1hTMoEoOgUxMOHbb3nxosKVr3Rwx9mO6U,4625
12
+ tunix/distillation/strategies/feature_pooling.py,sha256=itnHZ0QINnKBjg8-4c1Eewq6Gm3sYiEWAB2gSn2mkhU,6823
13
+ tunix/distillation/strategies/feature_projection.py,sha256=0zzJOSM_76oB-TwWwYUBXUEvORGRUIX4aV6S_7L4DM4,6497
14
+ tunix/distillation/strategies/logit.py,sha256=Z4x7JGY2XT43gOiSDd2bSkntUgWZdeNqog8su2gBhE8,4138
15
+ tunix/examples/data/translation_dataset.py,sha256=2g60f9uN9JykecSO3WHKeZ8KfKzv2-BPUYOmUvkhdyo,9271
16
+ tunix/generate/base_sampler.py,sha256=kL3IXt_yik1WPGTbxoXeZQ3Pw8Es3QRNRhkWINkrDWE,2054
17
+ tunix/generate/beam_search.py,sha256=se9zBmpBOoEXENgaJPgcPMhQoN77jYbJdk2ZK8_M-Ps,9722
18
+ tunix/generate/sampler.py,sha256=x52acyTzOcck6HpSKyXov_caFRuph8Wb2__v6cKsuWA,27007
19
+ tunix/generate/tokenizer_adapter.py,sha256=zsEsjOZvg32gb9SfWUVQT8yibCOtG4XSWV6zP_-cfVA,4326
20
+ tunix/generate/utils.py,sha256=2R3ILV9TLAtHZZt67SkKiyT7DBHzsk6o753iDH59nbI,18774
21
+ tunix/generate/vllm_sampler.py,sha256=IL1_burNb72j46GSmheGwqHTPyist3IrYWX8q2BEGJ0,10499
22
+ tunix/models/safetensors_loader.py,sha256=gyF6230EW7qaBJVtQZLTy5tbxaMrf4xUh27xrGl7Ips,5026
23
+ tunix/models/gemma/gemma.py,sha256=4ks6sLHxrQyEIA7bJV2oPKEQNYe5mAwD9u2PJ4NexjQ,28652
24
+ tunix/models/gemma/params.py,sha256=lHQa2cpMOKk6v1gnIKKe-IgihI0U1UYlJOo3uEAxJ8U,2442
25
+ tunix/models/gemma/params_safetensors.py,sha256=kN3YfKSNjKgZ7lSauVCjPdcSfrEjrd8huwQTttd2V9g,6905
26
+ tunix/models/gemma/sampler.py,sha256=w2xlax3N_WLEUb7fWebT5ZAwotU19nhwIwiIs0LS5W4,21736
27
+ tunix/models/gemma3/model.py,sha256=5BrfnL7nlzMcpNZHOFOmSpJq5TP3iNNssrclGOBC-_A,24243
28
+ tunix/models/gemma3/params.py,sha256=YCKf68VZONa0Vopm9e1-Kearf8AVoCte09DXE-IFinI,5501
29
+ tunix/models/gemma3/params_safetensors.py,sha256=cl0-Bfbs4GvGC6oGXaWm1xfI4Op2fDDx5JYetEVmAWU,7442
30
+ tunix/models/llama3/model.py,sha256=HKt1AIoPBx1DOqdLyn1JZatZW1uQKuOgeYegRm7dkdc,23319
31
+ tunix/models/llama3/params.py,sha256=7FJDCj56nRptkSqUbdT-T_I4y2dEaZsC3o7WF4myuHY,3374
32
+ tunix/models/qwen2/model.py,sha256=YyvHdNZiHLaQ3gGb1Dx_NiA1C5k0KOKKRtElwphLs2o,22266
33
+ tunix/models/qwen2/params.py,sha256=i_-W76RpqvN_bc4BoZ7P3ApZ_1Gd3HufEVYyASdPBQs,3483
34
+ tunix/models/qwen3/model.py,sha256=3GCwScMYAeHl_Zl_bxFGp5HPlwYp9dyal63_6qeMnKo,19697
35
+ tunix/models/qwen3/params.py,sha256=XQ-nVYQ9UwJ1kDGEK0nA4OlyFgmtDQ3yRlJnP7LKAmU,4656
36
+ tunix/oss/utils.py,sha256=JfoIYpHkB4qIM1JgoR8SeIuO5TzJ14z-8m5o2CsRPZY,859
37
+ tunix/rl/common.py,sha256=33OFG8NbXPzRypbyd-TpjCgWsEu1_ZTaYjs013RSw-k,10151
38
+ tunix/rl/reshard.py,sha256=uAe3r3h0W4NHsxNIHteUZwC74YgHFPWyYXeBv4ObHJM,5992
39
+ tunix/rl/rl_cluster.py,sha256=pnHZDwMHoI12OhK9KiGNlrMLOXyuIwpajuIHURncSxo,28079
40
+ tunix/rl/rl_learner.py,sha256=kkBXI_enhYyPegC7t9ShANrlyD3DaMhRMQek1sVpJiI,22379
41
+ tunix/rl/trainer.py,sha256=ZjwPpTnI90YXKJE49fWS_dSys16GU-EOpWDJpMMcRFY,3050
42
+ tunix/rl/utils.py,sha256=Km9WzQmuL8xHqxwnmL96-XFFZ3xgaV8rpKvaHpcr-uE,9232
43
+ tunix/rl/experimental/agentic/agents/agent_types.py,sha256=trqLQsMZYXdQyzTMh4bkdwowyJgb1UEwXRje5wsH6ps,3207
44
+ tunix/rl/experimental/agentic/agents/base_agent.py,sha256=hzPUb_xFxhBl7YnYh42s5I0LrFjV3HzyktK4sk_6SXY,8376
45
+ tunix/rl/experimental/agentic/agents/tool_agent.py,sha256=Ym7s7YWlpBPtmrRdutM7jGKHUxzOzJlmb9lTKpwNuPc,10089
46
+ tunix/rl/experimental/agentic/environments/base_environment.py,sha256=w-MS2coPItpKFPY0at9MlriUOX696jdIxJ0WE-N5t0A,5538
47
+ tunix/rl/experimental/agentic/environments/tool_environment.py,sha256=KWKZ3tqh4hMLRaFK662XgZIVSX_0B9d1iMuNmCalJ_M,8412
48
+ tunix/rl/experimental/agentic/parser/tool_parser/gemini_parser.py,sha256=aczEg3xgBZuaCDoRN_vv0JWbGAR1A1eMCoxSQqXJ8gA,601
49
+ tunix/rl/experimental/agentic/parser/tool_parser/qwen_parser.py,sha256=Z5LOCzQ94LMzn5S5olocXcfsMM2AJXpK_68Q7jl-Xc8,3306
50
+ tunix/rl/experimental/agentic/parser/tool_parser/tool_parser_base.py,sha256=7ht1eiuieuhEUY2-Y8tgCo5jqcnfvZRV0R3MuDcXVOw,2605
51
+ tunix/rl/experimental/agentic/parser/tool_parser/tool_parser_registry.py,sha256=3KX5uvhrbSVxDCDt2iTLy177qXzLeNNQC5-xLFOp84s,684
52
+ tunix/rl/experimental/agentic/prompts/prompt_template.py,sha256=JTFXmy3axxnk9Vd3gw7zW7UItaGsFEnzrTLVrygO5xA,1414
53
+ tunix/rl/experimental/agentic/rewards/reward.py,sha256=3srEyf7QkUyJj6QX6cWRXTAnRCVk90MjIXemWPh15u4,4354
54
+ tunix/rl/experimental/agentic/rewards/reward_types.py,sha256=eL5q5n0C7ArLMKx-CXRA8Euz6170Bqwd8trZEx7yvaA,1798
55
+ tunix/rl/experimental/agentic/tools/base_tool.py,sha256=5dJt-C1BTrplZZA_nKxDyKjlUi6sEtyzVXZBaHPIvRY,7238
56
+ tunix/rl/experimental/agentic/tools/calculator_tool.py,sha256=euTcCMkeTvN1GiDTmC34bSxF0QnKd6ioQ2FjWAlOcU8,3483
57
+ tunix/rl/experimental/agentic/tools/tool_manager.py,sha256=8HS3kQZ6gvJ3S6kjiTysbuBiDS8samDSmEdV63ffKD8,6586
58
+ tunix/rl/experimental/agentic/trajectory/trajectory_collect_engine.py,sha256=njJvTU6X2ery6z6p7erGBm9Hn_Nc7925o-O5cEEJhe4,8494
59
+ tunix/rl/grpo/grpo_helpers.py,sha256=A4Qr7N4KbfZuM5jJ_NXqAPLyOQjV5WNL3fKlC_U6F8s,1256
60
+ tunix/rl/grpo/grpo_learner.py,sha256=xHS3DvCnyrtdLIbfedyM-krHWCNDxpN6jNa4qpw02I8,16001
61
+ tunix/rl/inference/inference_worker.py,sha256=XoEXf0uYNfGaRk-Ao4SlL5XyDsEreiyt0TOgOCFOVAM,2831
62
+ tunix/rl/ppo/ppo_helpers.py,sha256=IgGw5T4POG90AdQHxxZ3HzM-_SUckSew9hsGUOMGa6w,4199
63
+ tunix/rl/ppo/ppo_learner.py,sha256=V7L3GBhrpon7iOwiH12M3gnivM9O9lt2Ohi-4U9Zda8,19063
64
+ tunix/rl/queue/data_queue.py,sha256=nEH3cGsfEWHBgcFaxP_aDLN_ZqpNb1FpSV7-OhWGUis,1797
65
+ tunix/rl/rollout/base_rollout.py,sha256=UNGtkqqkvKZPluNpqUpFuuQFVlIQ43ecwdidatmklkY,3476
66
+ tunix/rl/rollout/vanilla_rollout.py,sha256=6yoVRNMSYM1WHqN1xFgFtRVSMxnR4N6KGlqrvXt_PZ0,3589
67
+ tunix/rl/rollout/vllm_rollout.py,sha256=I5rAzNz2Fp8TJEJfPw4qVWkMqJEqUagyMJlGVc-5LI4,3666
68
+ tunix/sft/checkpoint_manager.py,sha256=iRvP2Wd4edCXL7R9VSRIfkequmh1q13g3SwXHMKT7rg,4354
69
+ tunix/sft/config.py,sha256=VNrWt6CUkCk-SJaf3-393tyXlImOkWlBP9NumjwJGeQ,13477
70
+ tunix/sft/hooks.py,sha256=WNkaJm4gRPB1KWz4PV8C0pn_lsXcmfeD0cSSKBbeh68,2232
71
+ tunix/sft/inflight_throttler.py,sha256=IIJdtJRwsWaApxXbTVCFUq4GqG4RS57TgOfqVTN2sJs,2124
72
+ tunix/sft/metrics_logger.py,sha256=Luo8IoW6ID6yH7ZTigpDI1IatCBQbwd8xZYDLwgEYgo,5845
73
+ tunix/sft/peft_main.py,sha256=HEiB-iKraJ6TDAQK5lH24O8-R4nYsSWrkbO1fV-kAmc,13466
74
+ tunix/sft/peft_trainer.py,sha256=n9ZpFYC11_d_XAi034-SYdfqMalzXOdwTZZuCKeNBNw,26447
75
+ tunix/sft/profiler.py,sha256=nWZmf9j_sxqli6aERoRhiJUFLw2OhhFWEIkOWFEv5Kw,3329
76
+ tunix/sft/progress_bar.py,sha256=3zkRWgo2peOc5s-54lvoCtKk3ULd4eQHAEERUdjGyuk,2465
77
+ tunix/sft/sharding_utils.py,sha256=-n3Ba7eUMYFuqEhFAqrk42_ZujLkLeatk6ZBoSb0Zlk,1544
78
+ tunix/sft/system_metrics_calculator.py,sha256=ziPoe1BgTdZCZ8DMDcw4sgu8vNfBBnnnVp-JIvf2J48,2506
79
+ tunix/sft/utils.py,sha256=MtZCezCXUdxnJDuY52Sd2MZ-QWnoYoLKuCrhIA2-TH8,1178
80
+ tunix/sft/dpo/dpo_trainer.py,sha256=ovXpjq7wjt353f3FCAuFxKZmGPYIZCbnTEfNv-fqhVM,15270
81
+ tunix/tests/test_common.py,sha256=1jZkMdIR3y0bKTaUygj1eWxyqOubjumLZl9b3T-Q5dc,6133
82
+ google_tunix-0.0.1.dist-info/METADATA,sha256=aRalgublhANE7VD2cMYR-F74svrzED_PvLSYW_UjLZk,6157
83
+ google_tunix-0.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
84
+ google_tunix-0.0.1.dist-info/top_level.txt,sha256=VOWD8y-ahrChIDAFYazDhmKAfJUyKY7C0Ovgpky4Z8Y,6
85
+ google_tunix-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1 @@
1
+ tunix
tunix/__init__.py ADDED
@@ -0,0 +1,28 @@
1
+ # Copyright 2024 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Tunix API."""
16
+
17
+ # pylint: disable=g-multiple-import, g-importing-member
18
+
19
+ from tunix.distillation.distillation_trainer import DistillationTrainer, TrainingConfig as DistillationTrainingConfig
20
+ from tunix.generate.sampler import CacheConfig, Sampler
21
+ from tunix.rl.grpo.grpo_learner import GrpoConfig, GrpoLearner, RewardFn
22
+ from tunix.rl.rl_cluster import ClusterConfig, RLCluster, RLTrainingConfig, Role
23
+ from tunix.rl.rollout.base_rollout import RolloutConfig
24
+ from tunix.sft.dpo.dpo_trainer import DpoTrainer, DpoTrainingConfig
25
+ from tunix.sft.metrics_logger import MetricsLogger, MetricsLoggerOptions
26
+ from tunix.sft.peft_trainer import PeftTrainer, TrainingConfig
27
+
28
+ # pylint: enable=g-multiple-import, g-importing-member
@@ -0,0 +1,20 @@
1
+ # Copyright 2025 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """Module containing the distillation trainers."""
15
+
16
+ # pylint: disable=g-importing-member
17
+
18
+ from tunix.distillation.distillation_trainer import DistillationTrainer
19
+ from tunix.distillation.distillation_trainer import TrainingConfig
20
+ from tunix.distillation.distillation_trainer import TrainingInput
@@ -0,0 +1,136 @@
1
+ # Copyright 2025 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Distillation trainer."""
16
+ import dataclasses
17
+ from typing import Any, Callable, Tuple
18
+
19
+ import flax
20
+ from flax import nnx
21
+ from jax.typing import ArrayLike # pylint: disable=g-importing-member
22
+ import optax
23
+ from tunix.distillation import strategies
24
+ from tunix.sft import metrics_logger
25
+ from tunix.sft import peft_trainer
26
+ from typing_extensions import override
27
+
28
+
29
+ @dataclasses.dataclass(slots=True, kw_only=True)
30
+ class TrainingConfig(peft_trainer.TrainingConfig):
31
+ """Distillation training config."""
32
+
33
+
34
+ @flax.struct.dataclass(frozen=True)
35
+ class TrainingInput(peft_trainer.TrainingInput):
36
+ """Distillation training input."""
37
+
38
+ teacher_output: Any = None
39
+
40
+
41
+ class DistillationTrainer(peft_trainer.PeftTrainer):
42
+ """Distillation trainer."""
43
+
44
+ def __init__(
45
+ self,
46
+ student_model: nnx.Module,
47
+ teacher_model: nnx.Module,
48
+ strategy: strategies.BaseStrategy,
49
+ optimizer: optax.GradientTransformation,
50
+ training_config: TrainingConfig,
51
+ ):
52
+ """Initializes the DistillationTrainer.
53
+
54
+ Args:
55
+ student_model: The student model to train.
56
+ teacher_model: The teacher model to use for distillation.
57
+ strategy: The distillation strategy to use.
58
+ optimizer: The optimizer to use for training.
59
+ training_config: The training config.
60
+ """
61
+ student_model, teacher_model = strategy.pre_process_models(
62
+ student_model, teacher_model
63
+ )
64
+ super().__init__(student_model, optimizer, training_config)
65
+ self.strategy = strategy
66
+ self.teacher_model = teacher_model
67
+ self.loss_fn = self.get_train_loss
68
+ self.eval_loss_fn = self.get_eval_loss
69
+ self.gen_model_input_fn = lambda x: {
70
+ "inputs": {"input_tokens": x.input_tokens, "input_mask": x.input_mask},
71
+ "teacher_output": (
72
+ x.teacher_output if hasattr(x, "teacher_output") else None
73
+ ),
74
+ }
75
+
76
+ @override
77
+ def with_gen_model_input_fn(
78
+ self, gen_model_input_fn: Callable[[Any], dict[str, ArrayLike]]
79
+ ) -> "DistillationTrainer":
80
+ self.gen_model_input_fn = lambda x: {
81
+ "inputs": gen_model_input_fn(x),
82
+ "teacher_output": (
83
+ x.teacher_output if hasattr(x, "teacher_output") else None
84
+ ),
85
+ }
86
+ return self
87
+
88
+ @override
89
+ def with_loss_fn(
90
+ self,
91
+ loss_fn: Callable[..., ArrayLike | Tuple[ArrayLike, Any]],
92
+ has_aux: bool = False,
93
+ ) -> "DistillationTrainer":
94
+ raise NotImplementedError(
95
+ "with_loss_fn is not supported for distillation. Use the strategy to"
96
+ " define the loss."
97
+ )
98
+
99
+ @override
100
+ def _prepare_inputs(self, input_data: TrainingInput) -> TrainingInput:
101
+ inputs = self.gen_model_input_fn(input_data)["inputs"]
102
+ if self._mode == metrics_logger.Mode.EVAL:
103
+ teacher_output = None
104
+ else:
105
+ teacher_output = self.strategy.get_teacher_outputs(
106
+ self.teacher_model, inputs
107
+ )
108
+
109
+ return TrainingInput(
110
+ input_tokens=input_data.input_tokens,
111
+ input_mask=input_data.input_mask,
112
+ teacher_output=teacher_output,
113
+ )
114
+
115
+ def get_train_loss(
116
+ self,
117
+ model: nnx.Module,
118
+ teacher_output: Any,
119
+ inputs: dict[str, ArrayLike],
120
+ ) -> ArrayLike:
121
+ return self.strategy.get_train_loss(model, teacher_output, inputs)
122
+
123
+ def get_eval_loss(
124
+ self,
125
+ model: nnx.Module,
126
+ teacher_output: Any,
127
+ inputs: dict[str, ArrayLike],
128
+ ) -> ArrayLike:
129
+ del teacher_output # Not computed in eval.
130
+ return self.strategy.get_eval_loss(model, inputs)
131
+
132
+ def close(self):
133
+ super().close()
134
+ self.model, self.teacher_model = self.strategy.post_process_models(
135
+ self.model, self.teacher_model
136
+ )
@@ -0,0 +1,25 @@
1
+ # Copyright 2025 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """Feature extraction utilities for distillation."""
15
+
16
+ # pylint: disable=g-importing-member
17
+
18
+ from tunix.distillation.feature_extraction.pooling import avg_pool_array_to_target_shape
19
+ from tunix.distillation.feature_extraction.projection import ModelWithFeatureProjection
20
+ from tunix.distillation.feature_extraction.projection import remove_feature_projection_from_models
21
+ from tunix.distillation.feature_extraction.projection import setup_models_with_feature_projection
22
+ from tunix.distillation.feature_extraction.sowed_module import pop_sowed_intermediate_outputs
23
+ from tunix.distillation.feature_extraction.sowed_module import SowedModule
24
+ from tunix.distillation.feature_extraction.sowed_module import unwrap_sowed_modules
25
+ from tunix.distillation.feature_extraction.sowed_module import wrap_model_with_sowed_modules