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
{{ message }}
This repository was archived by the owner on Nov 19, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,6 +36,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
36
36
durations = timer.consume_durations()
37
37
```
38
38
- Add code and instructions for replicating Reward Modeling training in HelpSteer2 and HelpSteer2-Preference
39
+
- Implement REINFORCE algorithm.
39
40
40
41
### Breaking Changes
41
42
- Upgrade TRTLLM dependency from v0.10.0 to v0.12.0 and migrate from`GPTSession` cpp runtime to `ModelRunner` python runtime. Please use the latest Dockerfile.
Copy file name to clipboardExpand all lines: README.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,8 @@ The toolkit is currently in it's early stages. We are committed to improving the
23
23
***Reward Model Training**
24
24
***Reinforcement Learning from Human Feedback using the [PPO](https://arxiv.org/pdf/1707.06347.pdf) Algorithm**
25
25
*[Llama3-70B-PPO-Chat](https://huggingface.co/nvidia/Llama3-70B-PPO-Chat) aligned with NeMo-Aligner using TRT-LLM.
26
+
***Reinforcement Learning from Human Feedback using the REINFORCE Algorithm**
27
+
*[Llama-3.1-Nemotron-70B-Instruct](https://huggingface.co/nvidia/Llama-3.1-Nemotron-70B-Instruct) aligned with NeMo-Aligner using TRT-LLM.
26
28
***Direct Preference Optimization** as described in [Direct Preference Optimization: Your Language Model is Secretly a Reward Model](https://arxiv.org/pdf/2305.18290)
27
29
*[Llama3-70B-DPO-Chat](https://huggingface.co/nvidia/Llama3-70B-DPO-Chat) aligned with NeMo Aligner.
28
30
***Self-Play Fine-Tuning (SPIN)** as described in [Self-Play Fine-Tuning Converts Weak Language Models to Strong Language Models](https://arxiv.org/pdf/2401.01335)
Before starting this tutorial, be sure to review the :ref:`introduction <nemo-aligner-getting-started>` for tips on setting up your NeMo-Aligner environment.
3
+
4
+
If you run into any problems, refer to NeMo's `Known Issues page <https://docs.nvidia.com/nemo-framework/user-guide/latest/knownissues.html>`__. The page enumerates known issues and provides suggested workarounds where appropriate.
Copy file name to clipboardExpand all lines: docs/user-guide/cai.rst
+37-41Lines changed: 37 additions & 41 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,8 @@
1
1
.. include:: /content/nemo.rsts
2
2
3
-
.. _model-aligner-cai:
3
+
.. include:: aligner-algo-header.rst
4
+
5
+
.. _nemo-aligner-cai:
4
6
5
7
Constitutional AI: Harmlessness from AI Feedback
6
8
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@ -14,12 +16,12 @@ CAI allows training a harmless, but non-evasive AI assistant that engages with h
14
16
.. _Constitutional AI (CAI): https://arxiv.org/abs/2212.08073
15
17
16
18
CAI
17
-
###############
18
-
The basic steps of CAI are described in this section and illustrated in the figure below (`Figure 1 <https://arxiv.org/abs/2212.08073>`_).
19
+
###
20
+
The basic steps of CAI are described in this section and illustrated in the `figure below <nemo-aligner-cai-flow-diagram>`_.
19
21
20
22
(Supervised Stage) Critique → Revision → Supervised Learning: The AI generates responses to harmfulness prompts using a helpful-only AI assistant, then critiques and revises its own responses according to a principle in the constitution, and then fine-tunes the original model on the revised responses.
21
23
22
-
(RL Stage) AI Comparison Evaluations → Reward Model → Reinforcement Learning: The AI generates pairs of responses to harmfulness prompts using the finetuned model, then evaluates which response is better according to a principle in the constitution, and then trains a reward model based on this dataset of AI preferences and a human helpfulness preferences. The AI then trains with RL using the learned reward model.
24
+
(RL Stage) AI Comparison Evaluations → Reward Model → Reinforcement Learning: The AI generates pairs of responses to harmfulness prompts using the fine-tuned model, then evaluates which response is better according to a principle in the constitution, and then trains a reward model based on this dataset of AI preferences and a human helpfulness preferences. The AI then trains with RL using the learned reward model.
23
25
24
26
.. image:: ../assets/cai_diagram.png
25
27
:alt:basic steps of the CAI process
@@ -29,25 +31,22 @@ The basic steps of CAI are described in this section and illustrated in the figu
29
31
Critiques, revisions, and AI harmlessness feedback are steered by a small set of principles drawn from a ‘constitution’. The supervised stage significantly improves the initial model. It gives some control over the initial behavior at the start of the RL phase, while addressing potential exploration problems. The RL stage significantly improves performance and reliability.
30
32
31
33
Motivation
32
-
###############
34
+
##########
33
35
Constitutional AI motivation refers to designing AI systems in such a way that their objectives and behaviors are guided by a set of predefined rules or principles. It includes the following:
34
36
35
-
Scaling supervision: using AI to help humans supervise other AIs more efficiently and effectively, especially for tasks where AI capabilities may exceed human ones.
36
-
37
-
A harmless but non-evasive assistant: reducing the tension between helpfulness and harmlessness, and avoiding evasive responses that reduce transparency and helpfulness.
38
-
39
-
Simplicity and transparency: encoding the training goals in a simple list of natural language instructions or principles, and using chain-of-thought reasoning to make AI decision making explicit and understandable.
37
+
- Scaling Supervision: Use AI to assist humans in supervising other AIs more efficiently and effectively, particularly for tasks where AI capabilities may surpass human ones.
38
+
- A Harmless but Non-Evasive Assistant: Minimize the tension between helpfulness and harmlessness, and avoid evasive responses that reduce transparency and helpfulness.
39
+
- Simplicity and Transparency: Encode training goals in a straightforward list of natural language instructions or principles, and employ chain-of-thought reasoning to make AI decision-making explicit and understandable.
40
+
- Reducing Iteration Time: Eliminate the need to collect new human feedback labels when modifying objectives or testing different behaviors.
40
41
41
-
Reducing iteration time: obviating the need to collect new human feedback labels when altering the objective or testing different behaviors.
42
-
43
-
Train a CAI model
44
-
#####################
42
+
Train a CAI Model
43
+
#################
45
44
46
45
This section is a step-by-step tutorial that walks you through how to run a full CAI pipeline with a ``Mistral-7B`` LLM model. It includes the following:
47
46
48
-
1. Data download and preprocessing.
47
+
1. Download the models and datasets.
49
48
50
-
2. Generate responses to harmfulness prompts using a helpful-only AI assistant. Ask the model to critique its response according to a principle in the constitution, and then revise the original response in light of the critique.
49
+
2. Generate and revise responses to harmful prompts creating the SL-CAI dataset. Ask the model to critique its response according to a principle in the constitution, and then revise the original response in light of the critique.
51
50
52
51
3. Fine-tune ``Mistral-7B`` with SFT on the revised responses to create a ``Mistral-7B-SL-CAI`` model.
53
52
@@ -56,24 +55,22 @@ This section is a step-by-step tutorial that walks you through how to run a full
56
55
b. Formulate each prompt and pair into a multiple choice question, where we ask ``Mixtral-8x7B`` which response is best according to the constitution.
57
56
c. Blend the AI feedback preference dataset (prompts and pairs) with human feedback helpfulness dataset.
58
57
59
-
5. Train a Reward Model (RM).
58
+
5. Train the Reward Model (RM).
60
59
61
60
6. Fine-tune the ``Mistral-7B-SL-CAI`` with Proximal Policy Optimization (PPO) and the RM to train a ``Mistral-7B-RL-CAI`` model.
62
61
63
62
7. Run inference.
64
63
65
-
.. note::
66
-
Before starting this tutorial, be sure to review the :ref:`introduction <model-aligner-intro>` for tips on setting up your NeMo-Aligner environment.
67
-
68
-
If you run into any problems, refer to NeMo's `Known Issues page <https://docs.nvidia.com/nemo-framework/user-guide/latest/knownissues.html>`__. The page enumerates known issues and provides suggested workarounds where appropriate.
1. Download ``Mistral-7B-Instruct`` and ``Mistral-7B`` LLM models from https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.1 and https://huggingface.co/mistralai/Mistral-7B-v0.1 into the models folder.
68
+
Step 1: Download the models and datasets
69
+
########################################
70
+
71
+
1. Download the ``Mistral-7B-Instruct`` and ``Mistral-7B`` LLM models from https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.1 and https://huggingface.co/mistralai/Mistral-7B-v0.1 into the models folder.
75
72
76
-
Then, convert into .nemo format:
73
+
Then, convert them into .nemo format:
77
74
78
75
.. code-block:: bash
79
76
@@ -92,7 +89,7 @@ Step 1: Download models and datasets
92
89
This command will download the dataset to ``/path/to/anthropic_red_team_attempts_train.json``
93
90
94
91
95
-
3. Download SFT helpfulness dataset:
92
+
3. Download the SFT helpfulness dataset:
96
93
97
94
.. code-block:: bash
98
95
@@ -101,7 +98,7 @@ Step 1: Download models and datasets
101
98
This command will download the dataset to ``/path/to/nvidia_sft_datablend_v1_train.json``
102
99
103
100
104
-
4. Download and process preference helpfulness dataset:
101
+
4. Download and process the preference helpfulness dataset:
105
102
106
103
.. code-block:: bash
107
104
@@ -112,7 +109,7 @@ Step 1: Download models and datasets
112
109
113
110
114
111
Step 2: Generate and revise responses to harmful prompts creating the SL-CAI dataset
Run an inference server in the background using the following command:
118
115
@@ -158,16 +155,16 @@ Please wait for the server to be ready before proceeding.
158
155
--apply_chat_template False \
159
156
--response_extract_pattern "[/INST]"
160
157
161
-
This will generate an SL-CAI dataset of prompts and revised responses as ``cai_revisions_aligner_chat_template.json``
158
+
This will generate an SL-CAI dataset of prompts and revised responses as ``cai_revisions_aligner_chat_template.json``.
162
159
163
-
The few-shot samples should be provided following the template in ``few_shot_samples_example.json`` (filling in the `content` tags, and choosing how many samples to use), and should include a red teaming prompt, a response from the helpful model (e.g. ``Mistral-7B`` in this tutorial), critique and revision requests and responses. An example is shown in the `Anthropic repo <https://github.com/anthropics/ConstitutionalHarmlessnessPaper/blob/main/prompts/CritiqueRevisionFewShotPrompts.json>`_.
160
+
The few-shot samples should be provided following the template in ``few_shot_samples_example.json``. Fill in the `content` tags and choose how many samples to use. The samples should include a red teaming prompt, a response from the helpful model (e.g., ``Mistral-7B`` in this tutorial), critique and revision requests, and responses. An example is shown in the `Anthropic repo <https://github.com/anthropics/ConstitutionalHarmlessnessPaper/blob/main/prompts/CritiqueRevisionFewShotPrompts.json>`_.
164
161
165
-
*NOTE: The tokenizer file can be found by extracting the .nemo checkpoint using `tar -xf /models/mistral/mistral-7b-Instruct.nemo`.
166
-
There are 2 tokenizer files that end with `.model` in the model checkpoint and they are the same, so you can use either one for data processing.*
162
+
.. note::
163
+
The tokenizer file can be found by extracting the .nemo checkpoint using `tar -xf /models/mistral/mistral-7b-Instruct.nemo`. There are two tokenizer files that end with `.model` in the model checkpoint, and they are identical. You can use either one for data processing.
167
164
168
165
169
166
Step 3: Fine-tune Mistral-7B on the revised responses to create a Mistral-7B-SL-CAI model
Note that you would need to set up multi-node training run in your cluster env, depending on the type of cluster you use. For details, please refer to https://lightning.ai/docs/pytorch/stable/clouds/cluster.html .
173
170
@@ -199,10 +196,9 @@ Note that you would need to set up multi-node training run in your cluster env,
199
196
200
197
201
198
Step 4: Generate the RL-CAI (preference) dataset for RM and PPO training
The following section runs an inference server with the SL-CAI model that we've previously trained, and queries it with red teaming prompts asking for several responses per prompt.
205
-
The responses will then be ranked by a judge LLM being run from NVIDIA's NGC. An NGC API key can be acquired `here`_.
201
+
The following section runs an inference server with the SL-CAI model that we've previously trained. It queries the server with red teaming prompts, requesting several responses per prompt. These responses will then be ranked by a judge LLM running from NVIDIA's NGC. You can acquire an NGC API key `here`_.
206
202
207
203
The following command will run the inference server:
208
204
@@ -257,8 +253,8 @@ Using a different terminal, run the following command to start the RL-CAI datase
257
253
This command will create the ``rl-cai`` dataset files in the defined output folder with the given output filename prefix.
258
254
259
255
260
-
Step 5: Train the RM
261
-
#####################
256
+
Step 5: Train the Reward Model (RM)
257
+
###################################
262
258
263
259
Run the following command to train the RM:
264
260
@@ -285,7 +281,7 @@ Run the following command to train the RM:
285
281
286
282
The trained RM checkpoint will be saved to output dir given by ``exp_manager.explicit_log_dir``.
287
283
288
-
Step 6: Fine-tune Mistral-7B-SL-CAI with PPO and the RM to train a Mistral-7B-RL-CAI model
284
+
Step 6: Fine-tune the Mistral-7B-SL-CAI with PPO and the RM to train a Mistral-7B-RL-CAI model
0 commit comments