You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Licensed under the Apache License, Version 2.0 (the "License");
5
+
you may not use this file except in compliance with the License.
6
+
You may obtain a copy of the License at
7
+
8
+
https://www.apache.org/licenses/LICENSE-2.0
9
+
10
+
Unless required by applicable law or agreed to in writing, software
11
+
distributed under the License is distributed on an "AS IS" BASIS,
12
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+
See the License for the specific language governing permissions and
14
+
limitations under the License.
15
+
-->
16
+
17
+
# Try GRPO with Pathways!
18
+
19
+
This tutorial demonstrates step-by-step instructions for setting up the environment and then training the Llama3.1 70B-IT model on the GSM8K math reasoning benchmark using Group Relative Policy Optimization (GRPO). GRPO can enhance your model's problem-solving skills on mathematical word problems, coding problems, etc.
20
+
21
+
GRPO is an RL algorithm designed to enhance the reasoning abilities of LLMs. It is a variant of Proximal Policy Optimization (PPO) that reduces memory usage by eliminating the need for a separate value function model. GRPO works by generating multiple responses for a given prompt, evaluating these responses using a reward model, and then calculating a relative advantage based on the group's performance to update the policy.
22
+
23
+
We use Tunix as the library for GRPO.
24
+
And we use vLLM as the library for efficient model inference and generation.
25
+
26
+
Furthermore, we use Pathways for [orchestration](https://cloud.google.com/ai-hypercomputer/docs/workloads/pathways-on-cloud/pathways-intro). Using Pathways, you can also run GRPO in a disaggregated mode where the trainer and the samplers are running on separate mesh. Try out the following recipe `v5p-64`. You can submit jobs to a Pathways enabled GKE cluster.
27
+
28
+
## Build and Upload MaxText Docker Image with Tunix, vLLM, tpu-commons dependencies
29
+
Run the following bash script to create a docker image with all the dependencies of MaxText, Tunix, vLLM and tpu-commons installed.
30
+
31
+
In addition to MaxText dependencies,
32
+
33
+
1. It installs `pip install keyring keyrings.google-artifactregistry-auth` which enables pip to authenticate with Google Artifact Registry automatically.
34
+
2. Next, it installs `vLLM` for Jax and TPUs from the artifact registry `https://us-python.pkg.dev/cloud-tpu-images/maxtext-rl/simple/`
35
+
3. Then, it installs `tpu-commons` from the same artifact registry.
36
+
37
+
38
+
`tpu_commons` is the TPU backend for vLLM. You will need both libraries to run vLLM on tpus.
39
+
We use the scheduler code from vLLM, and the model runner code from `tpu_commons`
40
+
41
+
```
42
+
bash docker_build_dependency_image.sh MODE=grpo
43
+
```
44
+
45
+
You can also use `bash docker_build_dependency_image.sh MODE=grpo-experimental` to try out new features via experimental dependencies such as improved pathwaysutils resharding API
46
+
47
+
48
+
49
+
### Upload the dependency docker image along with MaxText code
The overview of the demo script ~/maxtext/src/MaxText/examples/grpo_llama3_1_70b_demo_pw.py` is as follows:
66
+
67
+
1. We load a policy model and a reference model. Both are copies of `Llama3.1-70b-Instruct`.
68
+
2. Evaluate the policy model's performance on GSM8K math reasoning benchmark.
69
+
3. Train the policy model using GRPO with potentially different meshes for trainer and rollout dependending on the parameters `TRAINER_DEVICES_FRACTION` and `SAMPLER_DEVICES_FRACTION`. If we set both of these to `1.0`, the entire (same) mesh will be used for both trainer and rollout. If we set say `TRAINER_DEVICES_FRACTION=0.5` and `SAMPLER_DEVICES_FRACTION=0.5`, the first half of the devices will be used for trainer and the second half will be used for rollout
70
+
4. Evaluate the policy model's performance on GSM8K math reasoning benchmark after the post-training with GRPO.
0 commit comments