Update README.md
Browse files
README.md
CHANGED
@@ -1,205 +1,206 @@
|
|
1 |
-
---
|
2 |
-
license: other
|
3 |
-
license_name: nvidia-open-model-license
|
4 |
-
license_link: https://developer.download.nvidia.com/licenses/nvidia-open-model-license-agreement-june-2024.pdf
|
5 |
-
library_name: nemo
|
6 |
-
inference: false
|
7 |
-
fine-tuning: false
|
8 |
-
tags:
|
9 |
-
- nvidia
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
-
|
24 |
-
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
-
|
44 |
-
- 16x
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
import
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
"
|
78 |
-
"
|
79 |
-
"
|
80 |
-
"
|
81 |
-
"
|
82 |
-
"
|
83 |
-
"
|
84 |
-
"
|
85 |
-
"
|
86 |
-
"
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
response =
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
trainer.
|
124 |
-
trainer.
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
echo "
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
#SBATCH -
|
150 |
-
#SBATCH -
|
151 |
-
#SBATCH -
|
152 |
-
#SBATCH
|
153 |
-
#SBATCH --
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
|
181 |
-
|
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
|
186 |
-
|
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
|
192 |
-
|
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
|
197 |
-
|
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
|
|
|
1 |
+
---
|
2 |
+
license: other
|
3 |
+
license_name: nvidia-open-model-license
|
4 |
+
license_link: https://developer.download.nvidia.com/licenses/nvidia-open-model-license-agreement-june-2024.pdf
|
5 |
+
library_name: nemo
|
6 |
+
inference: false
|
7 |
+
fine-tuning: false
|
8 |
+
tags:
|
9 |
+
- nvidia
|
10 |
+
- text-generation
|
11 |
+
---
|
12 |
+
## Nemotron-4-340B-Base
|
13 |
+
|
14 |
+
[![Model architecture](https://img.shields.io/badge/Model%20Arch-Transformer%20Decoder-green)](#model-architecture)[![Model size](https://img.shields.io/badge/Params-340B-green)](#model-architecture)[![Language](https://img.shields.io/badge/Language-Multilingual-green)](#datasets)
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
### Model Overview:
|
19 |
+
|
20 |
+
Nemotron-4-340B-Base is a large language model (LLM) that can be used as part of a synthetic data generation pipeline to create training data that helps researchers and developers build their own LLMs. This model has 340 billion parameters, and supports a context length of 4,096 tokens. It is pre-trained for a total of 9 trillion tokens, consisting of a diverse assortment of English-based texts, 50+ natural languages and 40+ coding languages. After an initial pre-training phase of 8 trillion tokens, continuous pre-training of 1 trillion tokens was performed on top of the pre-trained model in order to improve model quality. During continuous pre-training, we altered the data composition by using a different distribution than the one seen at the beginning of training.
|
21 |
+
|
22 |
+
Under the NVIDIA Open Model License, NVIDIA confirms:
|
23 |
+
- Models are commercially usable.
|
24 |
+
- You are free to create and distribute Derivative Models.
|
25 |
+
- NVIDIA does not claim ownership to any outputs generated using the Models or Derivative Models
|
26 |
+
|
27 |
+
|
28 |
+
### License:
|
29 |
+
|
30 |
+
[NVIDIA Open Model License](https://developer.download.nvidia.com/licenses/nvidia-open-model-license-agreement-june-2024.pdf)
|
31 |
+
|
32 |
+
### Intended use
|
33 |
+
|
34 |
+
Nemotron-4-340B-Base is a completion model intended for use in over 50+ natural and 40+ coding languages. It is compatible with [NVIDIA NeMo Framework](https://docs.nvidia.com/nemo-framework/index.html). For best performance on a given task, users are encouraged to customize the model using the NeMo Framework suite of customization tools including Parameter-Efficient Fine-Tuning (P-tuning, Adapters, LoRA, and more), and Model Alignment (SFT, SteerLM, RLHF, and more) using [NeMo-Aligner](https://github.com/NVIDIA/NeMo-Aligner). Refer to the [documentation](https://docs.nvidia.com/nemo-framework/user-guide/latest/llms/nemotron/index.html) for examples.
|
35 |
+
|
36 |
+
**Model Developer:** NVIDIA
|
37 |
+
|
38 |
+
**Model Dates:** Nemotron-4-340B-Base was trained between December 2023 and May 2024.
|
39 |
+
|
40 |
+
### Required Hardware
|
41 |
+
|
42 |
+
BF16 Inference:
|
43 |
+
- 8x H200 (1x H200 node)
|
44 |
+
- 16x H100 (2x H100 nodes)
|
45 |
+
- 16x A100 80GB (2x A100 80GB nodes)
|
46 |
+
|
47 |
+
### Model Architecture:
|
48 |
+
|
49 |
+
Nemotron-4-340B-Base is trained with a global batch-size of 2304, a sequence length of 4096 tokens, uses Grouped-Query Attention (GQA), and Rotary Position Embeddings (RoPE).
|
50 |
+
|
51 |
+
**Architecture Type:** Transformer Decoder (auto-regressive language model)
|
52 |
+
|
53 |
+
**Network Architecture:**
|
54 |
+
Nemotron-4
|
55 |
+
|
56 |
+
### Usage
|
57 |
+
|
58 |
+
Deployment and inference with Nemotron-4-340B-Base can be done in three steps using NeMo Framework:
|
59 |
+
|
60 |
+
1. Create a Python script to interact with the deployed model.
|
61 |
+
2. Create a Bash script to start the inference server.
|
62 |
+
3. Schedule a Slurm job to distribute the model across 2 nodes and associate them with the inference server.
|
63 |
+
|
64 |
+
The first task is for the Python Script.
|
65 |
+
|
66 |
+
1. Define the Python script ``call_server.py``
|
67 |
+
|
68 |
+
```python
|
69 |
+
import requests
|
70 |
+
import json
|
71 |
+
headers = {"Content-Type": "application/json"}
|
72 |
+
def text_generation(data, ip='localhost', port=None):
|
73 |
+
resp = requests.put(f'http://{ip}:{port}/generate', data=json.dumps(data), headers=headers)
|
74 |
+
return resp.json()
|
75 |
+
def get_generation(prompt, greedy, add_BOS, token_to_gen, min_tokens, temp, top_p, top_k, repetition, batch=False):
|
76 |
+
data = {
|
77 |
+
"sentences": [prompt] if not batch else prompt,
|
78 |
+
"tokens_to_generate": int(token_to_gen),
|
79 |
+
"temperature": temp,
|
80 |
+
"add_BOS": add_BOS,
|
81 |
+
"top_k": top_k,
|
82 |
+
"top_p": top_p,
|
83 |
+
"greedy": greedy,
|
84 |
+
"all_probs": False,
|
85 |
+
"repetition_penalty": repetition,
|
86 |
+
"min_tokens_to_generate": int(min_tokens),
|
87 |
+
"end_strings": ["<|endoftext|>", "<extra_id_1>", "\x11", "<extra_id_1>User"],
|
88 |
+
}
|
89 |
+
sentences = text_generation(data, port=1424)['sentences']
|
90 |
+
return sentences[0] if not batch else sentences
|
91 |
+
PROMPT_TEMPLATE = "{prompt}"
|
92 |
+
question = "Write a poem on NVIDIA in the style of Shakespeare"
|
93 |
+
prompt = PROMPT_TEMPLATE.format(prompt=question)
|
94 |
+
print(prompt)
|
95 |
+
response = get_generation(prompt, greedy=True, add_BOS=False, token_to_gen=1024, min_tokens=1, temp=1.0, top_p=1.0, top_k=0, repetition=1.0, batch=False)
|
96 |
+
response = response[len(prompt):]
|
97 |
+
print(response)
|
98 |
+
```
|
99 |
+
|
100 |
+
|
101 |
+
2. Given this Python script, create a Bash script which spins up the inference server within the [NeMo container](https://catalog.ngc.nvidia.com/orgs/nvidia/containers/nemo) (```docker pull nvcr.io/nvidia/nemo:24.05```) and calls the Python script ``call_server.py``. The Bash script ``nemo_inference.sh`` is as follows:
|
102 |
+
|
103 |
+
|
104 |
+
```bash
|
105 |
+
NEMO_FILE=$1
|
106 |
+
WEB_PORT=1424
|
107 |
+
depends_on () {
|
108 |
+
HOST=$1
|
109 |
+
PORT=$2
|
110 |
+
STATUS=$(curl -X PUT http://$HOST:$PORT >/dev/null 2>/dev/null; echo $?)
|
111 |
+
while [ $STATUS -ne 0 ]
|
112 |
+
do
|
113 |
+
echo "waiting for server ($HOST:$PORT) to be up"
|
114 |
+
sleep 10
|
115 |
+
STATUS=$(curl -X PUT http://$HOST:$PORT >/dev/null 2>/dev/null; echo $?)
|
116 |
+
done
|
117 |
+
echo "server ($HOST:$PORT) is up running"
|
118 |
+
}
|
119 |
+
/usr/bin/python3 /opt/NeMo/examples/nlp/language_modeling/megatron_gpt_eval.py \
|
120 |
+
gpt_model_file=$NEMO_FILE \
|
121 |
+
pipeline_model_parallel_split_rank=0 \
|
122 |
+
server=True tensor_model_parallel_size=8 \
|
123 |
+
trainer.precision=bf16 pipeline_model_parallel_size=2 \
|
124 |
+
trainer.devices=8 \
|
125 |
+
trainer.num_nodes=2 \
|
126 |
+
web_server=False \
|
127 |
+
port=${WEB_PORT} &
|
128 |
+
SERVER_PID=$!
|
129 |
+
readonly local_rank="${LOCAL_RANK:=${SLURM_LOCALID:=${OMPI_COMM_WORLD_LOCAL_RANK:-}}}"
|
130 |
+
if [ $SLURM_NODEID -eq 0 ] && [ $local_rank -eq 0 ]; then
|
131 |
+
depends_on "0.0.0.0" ${WEB_PORT}
|
132 |
+
echo "start get json"
|
133 |
+
sleep 5
|
134 |
+
echo "SLURM_NODEID: $SLURM_NODEID"
|
135 |
+
echo "local_rank: $local_rank"
|
136 |
+
/usr/bin/python3 /scripts/call_server.py
|
137 |
+
echo "clean up dameons: $$"
|
138 |
+
kill -9 $SERVER_PID
|
139 |
+
pkill python
|
140 |
+
fi
|
141 |
+
wait
|
142 |
+
```
|
143 |
+
|
144 |
+
|
145 |
+
3. Launch ``nemo_inference.sh`` with a Slurm script defined like below, which starts a 2-node job for model inference.
|
146 |
+
|
147 |
+
```bash
|
148 |
+
#!/bin/bash
|
149 |
+
#SBATCH -A SLURM-ACCOUNT
|
150 |
+
#SBATCH -p SLURM-PARITION
|
151 |
+
#SBATCH -N 2
|
152 |
+
#SBATCH -J generation
|
153 |
+
#SBATCH --ntasks-per-node=8
|
154 |
+
#SBATCH --gpus-per-node=8
|
155 |
+
set -x
|
156 |
+
RESULTS=<PATH_TO_YOUR_SCRIPTS_FOLDER>
|
157 |
+
OUTFILE="${RESULTS}/slurm-%j-%n.out"
|
158 |
+
ERRFILE="${RESULTS}/error-%j-%n.out"
|
159 |
+
MODEL=<PATH_TO>/Nemotron-4-340B-Base
|
160 |
+
CONTAINER="nvcr.io/nvidia/nemo:24.05"
|
161 |
+
MOUNTS="--container-mounts=<PATH_TO_YOUR_SCRIPTS_FOLDER>:/scripts,MODEL:/model"
|
162 |
+
read -r -d '' cmd <<EOF
|
163 |
+
bash /scripts/nemo_inference.sh /model
|
164 |
+
EOF
|
165 |
+
srun -o $OUTFILE -e $ERRFILE --container-image="$CONTAINER" $MOUNTS bash -c "${cmd}"
|
166 |
+
```
|
167 |
+
|
168 |
+
|
169 |
+
### Dataset & Training
|
170 |
+
|
171 |
+
The training corpus for Nemotron-4-340B-Base consists of English and multilingual text, as well as code. Our sources cover a variety of document types such as: webpages, dialogue, articles, and other written materials. The corpus spans domains including legal, math, science, finance, and more. In our continued training set, we introduce a small portion of question-answering, and alignment style data to improve model performance.
|
172 |
+
|
173 |
+
**Data Freshness:** The pretraining data has a cutoff of June 2023.
|
174 |
+
|
175 |
+
### Evaluation Results
|
176 |
+
|
177 |
+
#### Overview
|
178 |
+
|
179 |
+
*5-shot performance.* Language Understanding evaluated using Massive Multitask Language Understanding:
|
180 |
+
| Average |
|
181 |
+
| :------------- |
|
182 |
+
| 81.1 |
|
183 |
+
|
184 |
+
*Zero-shot performance.* Evaluated using select datasets from the LM Evaluation Harness with additions:
|
185 |
+
| HellaSwag | Winogrande | BBH| ARC-Challenge |
|
186 |
+
| :------------- | :------------- | :------------- | :------------- |
|
187 |
+
| 90.53 | 89.50 | 85.44 | 94.28 |
|
188 |
+
|
189 |
+
*Chain of Thought (CoT)*. Multilingual capabilities evaluated using Multilingual Grade School Math:
|
190 |
+
|
191 |
+
| ES Exact Match (%) | JA Exact Match (%) | TH Exact Match (%) |
|
192 |
+
| :------------- | :------------- | :------------- |
|
193 |
+
| 68.8 | 69.6 | 68.4 |
|
194 |
+
|
195 |
+
*Code generation performance*. Evaluated using HumanEval:
|
196 |
+
| p@1, 0-Shot |
|
197 |
+
| :------------- |
|
198 |
+
| 57.3 |
|
199 |
+
|
200 |
+
### Limitations
|
201 |
+
|
202 |
+
The model was trained on data that contains toxic language, unsafe content, and societal biases originally crawled from the internet. Therefore, the model may amplify those biases and return toxic responses especially when prompted with toxic prompts. The model may generate answers that may be inaccurate, omit key information, or include irrelevant or redundant text producing socially unacceptable or undesirable text, even if the prompt itself does not include anything explicitly offensive.
|
203 |
+
|
204 |
+
### Ethical Considerations
|
205 |
+
|
206 |
+
NVIDIA believes Trustworthy AI is a shared responsibility and we have established policies and practices to enable development for a wide array of AI applications. When downloaded or used in accordance with our terms of service, developers should work with their internal model team to ensure this model meets requirements for the relevant industry and use case and addresses unforeseen product misuse. For more detailed information on ethical considerations for this model, please see the Model Card++ Explainability, Bias, Safety & Security, and Privacy Subcards [here.](https://catalog.ngc.nvidia.com/orgs/nvidia/teams/nemo/models/nemotron-4-340b-base). Please report security vulnerabilities or NVIDIA AI Concerns [here](https://www.nvidia.com/en-us/support/submit-security-vulnerability/).
|