Text Generation
GGUF
English
nvidia-nemotron
hierarchical-reasoning
mixture-of-experts
multi-modal
autonomous-code-execution
chain-of-thought
amd-rocm
humanitys-last-exam
ollama
conversational
Instructions to use kings1/Nova with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use kings1/Nova with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf kings1/Nova:Q4_K_M # Run inference directly in the terminal: llama cli -hf kings1/Nova:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf kings1/Nova:Q4_K_M # Run inference directly in the terminal: llama cli -hf kings1/Nova:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf kings1/Nova:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf kings1/Nova:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf kings1/Nova:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf kings1/Nova:Q4_K_M
Use Docker
docker model run hf.co/kings1/Nova:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use kings1/Nova with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "kings1/Nova" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "kings1/Nova", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/kings1/Nova:Q4_K_M
- Ollama
How to use kings1/Nova with Ollama:
ollama run hf.co/kings1/Nova:Q4_K_M
- Unsloth Desktop
- Docker Model Runner
How to use kings1/Nova with Docker Model Runner:
docker model run hf.co/kings1/Nova:Q4_K_M
- Lemonade
How to use kings1/Nova with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull kings1/Nova:Q4_K_M
Run and chat with the model
lemonade run user.Nova-Q4_K_M
List all available models
lemonade list
- Atomic Chat
Upload folder using huggingface_hub
Browse files- README.md +2 -2
- data/ultrachat_200k/.gitattributes +55 -0
- data/ultrachat_200k/README.md +124 -0
- data/ultrachat_200k/data/test_gen-00000-of-00001-3d4cd8309148a71f.parquet +3 -0
- data/ultrachat_200k/data/test_sft-00000-of-00001-f7dfac4afe5b93f4.parquet +3 -0
- data/ultrachat_200k/data/train_gen-00000-of-00003-a6c9fb894be3e50b.parquet +3 -0
- data/ultrachat_200k/data/train_gen-00001-of-00003-d6a0402e417f35ca.parquet +3 -0
- data/ultrachat_200k/data/train_gen-00002-of-00003-c0db75b92a2f48fd.parquet +3 -0
- data/ultrachat_200k/data/train_sft-00000-of-00003-a3ecf92756993583.parquet +3 -0
- data/ultrachat_200k/data/train_sft-00001-of-00003-0a1804bcb6ae68c6.parquet +3 -0
- data/ultrachat_200k/data/train_sft-00002-of-00003-ee46ed25cfae92c6.parquet +3 -0
- scripts/train_moe_multidomain.py +135 -0
README.md
CHANGED
|
@@ -14,9 +14,9 @@ metrics:
|
|
| 14 |
- accuracy
|
| 15 |
---
|
| 16 |
|
| 17 |
-
# π Nova MoE-Vision β Ground-Up Hierarchical Reasoning Engine
|
| 18 |
|
| 19 |
-
**Nova MoE-Vision** are ground-up custom AI models built from scratch, combining:
|
| 20 |
1. **Hierarchical Reasoning Model (HRM)**: Dual multi-timescale recurrent engine ($f_H$ and $f_L$).
|
| 21 |
2. **Sparse Mixture of Experts (MoE)**: 8 SwiGLU FFN Experts with Top-2 Router Gating (~522.8 Million Total Parameters).
|
| 22 |
3. **Multi-Modal Vision Projection**: Linear projection mapping image features into token embedding space.
|
|
|
|
| 14 |
- accuracy
|
| 15 |
---
|
| 16 |
|
| 17 |
+
# π Nova 1.0 & Nova 2.0 MoE-Vision β Ground-Up Hierarchical Reasoning Engine
|
| 18 |
|
| 19 |
+
**Nova 1.0 & Nova 2.0 MoE-Vision** are ground-up custom AI models built from scratch, combining:
|
| 20 |
1. **Hierarchical Reasoning Model (HRM)**: Dual multi-timescale recurrent engine ($f_H$ and $f_L$).
|
| 21 |
2. **Sparse Mixture of Experts (MoE)**: 8 SwiGLU FFN Experts with Top-2 Router Gating (~522.8 Million Total Parameters).
|
| 22 |
3. **Multi-Modal Vision Projection**: Linear projection mapping image features into token embedding space.
|
data/ultrachat_200k/.gitattributes
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.lz4 filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
# Audio files - uncompressed
|
| 38 |
+
*.pcm filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
*.sam filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
*.raw filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
# Audio files - compressed
|
| 42 |
+
*.aac filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
*.flac filter=lfs diff=lfs merge=lfs -text
|
| 44 |
+
*.mp3 filter=lfs diff=lfs merge=lfs -text
|
| 45 |
+
*.ogg filter=lfs diff=lfs merge=lfs -text
|
| 46 |
+
*.wav filter=lfs diff=lfs merge=lfs -text
|
| 47 |
+
# Image files - uncompressed
|
| 48 |
+
*.bmp filter=lfs diff=lfs merge=lfs -text
|
| 49 |
+
*.gif filter=lfs diff=lfs merge=lfs -text
|
| 50 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
| 51 |
+
*.tiff filter=lfs diff=lfs merge=lfs -text
|
| 52 |
+
# Image files - compressed
|
| 53 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 54 |
+
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 55 |
+
*.webp filter=lfs diff=lfs merge=lfs -text
|
data/ultrachat_200k/README.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
license: mit
|
| 5 |
+
size_categories:
|
| 6 |
+
- 100K<n<1M
|
| 7 |
+
task_categories:
|
| 8 |
+
- text-generation
|
| 9 |
+
pretty_name: UltraChat 200k
|
| 10 |
+
configs:
|
| 11 |
+
- config_name: default
|
| 12 |
+
data_files:
|
| 13 |
+
- split: train_sft
|
| 14 |
+
path: data/train_sft-*
|
| 15 |
+
- split: test_sft
|
| 16 |
+
path: data/test_sft-*
|
| 17 |
+
- split: train_gen
|
| 18 |
+
path: data/train_gen-*
|
| 19 |
+
- split: test_gen
|
| 20 |
+
path: data/test_gen-*
|
| 21 |
+
dataset_info:
|
| 22 |
+
features:
|
| 23 |
+
- name: prompt
|
| 24 |
+
dtype: string
|
| 25 |
+
- name: prompt_id
|
| 26 |
+
dtype: string
|
| 27 |
+
- name: messages
|
| 28 |
+
list:
|
| 29 |
+
- name: content
|
| 30 |
+
dtype: string
|
| 31 |
+
- name: role
|
| 32 |
+
dtype: string
|
| 33 |
+
splits:
|
| 34 |
+
- name: train_sft
|
| 35 |
+
num_bytes: 1397058554
|
| 36 |
+
num_examples: 207865
|
| 37 |
+
- name: test_sft
|
| 38 |
+
num_bytes: 154695659
|
| 39 |
+
num_examples: 23110
|
| 40 |
+
- name: train_gen
|
| 41 |
+
num_bytes: 1347396812
|
| 42 |
+
num_examples: 256032
|
| 43 |
+
- name: test_gen
|
| 44 |
+
num_bytes: 148276089
|
| 45 |
+
num_examples: 28304
|
| 46 |
+
download_size: 1624049723
|
| 47 |
+
dataset_size: 3047427114
|
| 48 |
+
---
|
| 49 |
+
|
| 50 |
+
# Dataset Card for UltraChat 200k
|
| 51 |
+
|
| 52 |
+
## Dataset Description
|
| 53 |
+
|
| 54 |
+
This is a heavily filtered version of the [UltraChat](https://github.com/thunlp/UltraChat) dataset and was used to train [Zephyr-7B-Ξ²](https://huggingface.co/HuggingFaceH4/zephyr-7b-beta), a state of the art 7b chat model.
|
| 55 |
+
|
| 56 |
+
The original datasets consists of 1.4M dialogues generated by ChatGPT and spanning a wide range of topics. To create `UltraChat 200k`, we applied the following logic:
|
| 57 |
+
|
| 58 |
+
- Selection of a subset of data for faster supervised fine tuning.
|
| 59 |
+
- Truecasing of the dataset, as we observed around 5% of the data contained grammatical errors like "Hello. how are you?" instead of "Hello. How are you?"
|
| 60 |
+
- Removal of dialogues where the assistant replies with phrases like "I do not have emotions" or "I don't have opinions", even for fact-based prompts that don't involve either.
|
| 61 |
+
|
| 62 |
+
## Dataset Structure
|
| 63 |
+
|
| 64 |
+
The dataset has four splits, suitable for:
|
| 65 |
+
|
| 66 |
+
* Supervised fine-tuning (`sft`).
|
| 67 |
+
* Generation ranking (`gen`) via techniques like rejection sampling or PPO.
|
| 68 |
+
|
| 69 |
+
The number of examples per split is shown as follows:
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
| train_sft | test_sft | train_gen | test_gen |
|
| 73 |
+
|:-------:|:-----------:|:-----:| :-----:|
|
| 74 |
+
| 207865 | 23110 | 256032 | 28304 |
|
| 75 |
+
|
| 76 |
+
The dataset is stored in parquet format with each entry using the following schema:
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
{
|
| 80 |
+
"prompt": "Create a fully-developed protagonist who is challenged to survive within a dystopian society under the rule of a tyrant. ...",
|
| 81 |
+
"messages":[
|
| 82 |
+
{
|
| 83 |
+
"content": "Create a fully-developed protagonist who is challenged to survive within a dystopian society under the rule of a tyrant. ...",
|
| 84 |
+
"role": "user"
|
| 85 |
+
},
|
| 86 |
+
{
|
| 87 |
+
"content": "Name: Ava\n\n Ava was just 16 years old when the world as she knew it came crashing down. The government had collapsed, leaving behind a chaotic and lawless society. ...",
|
| 88 |
+
"role": "assistant"
|
| 89 |
+
},
|
| 90 |
+
{
|
| 91 |
+
"content": "Wow, Ava's story is so intense and inspiring! Can you provide me with more details. ...",
|
| 92 |
+
"role": "user"
|
| 93 |
+
},
|
| 94 |
+
{
|
| 95 |
+
"content": "Certainly! ....",
|
| 96 |
+
"role": "assistant"
|
| 97 |
+
},
|
| 98 |
+
{
|
| 99 |
+
"content": "That's really interesting! I would love to hear more...",
|
| 100 |
+
"role": "user"
|
| 101 |
+
}
|
| 102 |
+
{
|
| 103 |
+
"content": "Certainly! ....",
|
| 104 |
+
"role": "assistant"
|
| 105 |
+
},
|
| 106 |
+
],
|
| 107 |
+
"prompt_id": "d938b65dfe31f05f80eb8572964c6673eddbd68eff3db6bd234d7f1e3b86c2af"
|
| 108 |
+
}
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
## Citation
|
| 112 |
+
|
| 113 |
+
If you find this dataset is useful in your work, please cite the original UltraChat dataset:
|
| 114 |
+
|
| 115 |
+
```
|
| 116 |
+
@misc{ding2023enhancing,
|
| 117 |
+
title={Enhancing Chat Language Models by Scaling High-quality Instructional Conversations},
|
| 118 |
+
author={Ning Ding and Yulin Chen and Bokai Xu and Yujia Qin and Zhi Zheng and Shengding Hu and Zhiyuan Liu and Maosong Sun and Bowen Zhou},
|
| 119 |
+
year={2023},
|
| 120 |
+
eprint={2305.14233},
|
| 121 |
+
archivePrefix={arXiv},
|
| 122 |
+
primaryClass={cs.CL}
|
| 123 |
+
}
|
| 124 |
+
```
|
data/ultrachat_200k/data/test_gen-00000-of-00001-3d4cd8309148a71f.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:937211dbe6e7db6315cd894efaedfe0231198a211ed5a1f856b0553a4b3844c0
|
| 3 |
+
size 80359907
|
data/ultrachat_200k/data/test_sft-00000-of-00001-f7dfac4afe5b93f4.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c18fd6e77395577652bdefbc5a87044ea799e989451ecfca5c6cf977ae5c6f70
|
| 3 |
+
size 81176553
|
data/ultrachat_200k/data/train_gen-00000-of-00003-a6c9fb894be3e50b.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8172417116ff18bb0d1ecc2166a658ebabf79a6c9cf02d8cad411fa764548663
|
| 3 |
+
size 243687391
|
data/ultrachat_200k/data/train_gen-00001-of-00003-d6a0402e417f35ca.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8b9e9ce202df576400e6727fcabb027bc92449767bec00871190d81f1b330de1
|
| 3 |
+
size 243300397
|
data/ultrachat_200k/data/train_gen-00002-of-00003-c0db75b92a2f48fd.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1fe9ba24c1bc2be447041e93aaca4689342e25470e6dedd4101019decf151922
|
| 3 |
+
size 243497356
|
data/ultrachat_200k/data/train_sft-00000-of-00003-a3ecf92756993583.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:afa8fa7426081b2a0e732fb50dbb5cd402a28ad5f0dbe66c0d996d63e7220727
|
| 3 |
+
size 243999189
|
data/ultrachat_200k/data/train_sft-00001-of-00003-0a1804bcb6ae68c6.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c8230190bc8b29084c974ff32f05589b458fad1908fc4b2fb2b9e1e9f7921f03
|
| 3 |
+
size 243897199
|
data/ultrachat_200k/data/train_sft-00002-of-00003-ee46ed25cfae92c6.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6fe7d2a5e95cf660f972ecaf304aa5632d7f53384e4b0e0d0f44d9c96733c03e
|
| 3 |
+
size 244131731
|
scripts/train_moe_multidomain.py
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Nova 2.0 MoE-Vision β Large-Scale Multi-Domain GPU Pre-Training Script
|
| 3 |
+
Trains 522.8M Nova 2.0 MoE-Vision Model on AMD ROCm GPU (96 GB VRAM)
|
| 4 |
+
across ultrachat_200k dataset downloaded via official 'hf' CLI.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
import sys
|
| 9 |
+
import argparse
|
| 10 |
+
import random
|
| 11 |
+
import torch
|
| 12 |
+
import torch.nn as nn
|
| 13 |
+
|
| 14 |
+
# Add project root to sys.path
|
| 15 |
+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
| 16 |
+
|
| 17 |
+
from config.model_config import Nova1Config
|
| 18 |
+
from src.tokenizer.bpe_tokenizer import Nova1Tokenizer
|
| 19 |
+
from src.model.nova2_moe_vision import Nova2MoEVision
|
| 20 |
+
from src.dataset.hf_dataset import create_hf_dataloader
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def main():
|
| 24 |
+
parser = argparse.ArgumentParser(description="Pre-train Nova 2.0 MoE-Vision Model")
|
| 25 |
+
parser.add_argument("--tokenizer_path", type=str, default="checkpoints/nova1_gemini_tokenizer.json", help="Tokenizer JSON")
|
| 26 |
+
parser.add_argument("--epochs", type=int, default=5, help="Number of training epochs")
|
| 27 |
+
parser.add_argument("--batch_size", type=int, default=8, help="Batch size per step")
|
| 28 |
+
parser.add_argument("--lr", type=float, default=2e-4, help="Learning rate")
|
| 29 |
+
parser.add_argument("--num_experts", type=int, default=8, help="Number of MoE Experts")
|
| 30 |
+
parser.add_argument("--top_k", type=int, default=2, help="Top-K active experts per token")
|
| 31 |
+
parser.add_argument("--max_samples", type=int, default=20000, help="Max dataset samples")
|
| 32 |
+
args = parser.parse_args()
|
| 33 |
+
|
| 34 |
+
token = os.environ.get("HF_TOKEN")
|
| 35 |
+
tokenizer = Nova1Tokenizer.load(args.tokenizer_path)
|
| 36 |
+
print(f"Loaded 32K Tokenizer from '{args.tokenizer_path}'.", flush=True)
|
| 37 |
+
|
| 38 |
+
# Nova 2.0 MoE Config (~522.8M Parameters)
|
| 39 |
+
config = Nova1Config(
|
| 40 |
+
vocab_size=tokenizer.vocab_size,
|
| 41 |
+
d_model=768,
|
| 42 |
+
n_heads=12,
|
| 43 |
+
d_ff=3072,
|
| 44 |
+
n_layers_L=4,
|
| 45 |
+
n_layers_H=4,
|
| 46 |
+
max_seq_len=512,
|
| 47 |
+
learning_rate=args.lr,
|
| 48 |
+
device="cuda" if torch.cuda.is_available() else "cpu",
|
| 49 |
+
dtype="bfloat16"
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
print(f"\n=======================================================", flush=True)
|
| 53 |
+
print(f"π Launching Nova 2.0 Sparse MoE Multi-Domain Engine", flush=True)
|
| 54 |
+
print(f"Device: {config.device.upper()} | Experts: {args.num_experts} (Top-{args.top_k}) | Precision: {config.dtype}", flush=True)
|
| 55 |
+
print(f"=======================================================\n", flush=True)
|
| 56 |
+
|
| 57 |
+
model = Nova2MoEVision(config, num_experts=args.num_experts, top_k=args.top_k, vision_dim=768).to(config.device)
|
| 58 |
+
|
| 59 |
+
# Load previous Nova 2.0 MoE checkpoint if available
|
| 60 |
+
if os.path.exists("checkpoints/nova2_moe_final.pt"):
|
| 61 |
+
try:
|
| 62 |
+
ckpt = torch.load("checkpoints/nova2_moe_final.pt", map_location="cpu", weights_only=False)
|
| 63 |
+
model.load_state_dict(ckpt["model_state"], strict=False)
|
| 64 |
+
print("Loaded warm-start weights from 'checkpoints/nova2_moe_final.pt'.", flush=True)
|
| 65 |
+
except Exception as e:
|
| 66 |
+
print(f"Notice loading checkpoint: {e}", flush=True)
|
| 67 |
+
|
| 68 |
+
num_params = sum(p.numel() for p in model.parameters())
|
| 69 |
+
print(f"π Nova 2.0 MoE Total Parameters: {num_params:,} (~{num_params / 1e6:.1f} Million)", flush=True)
|
| 70 |
+
|
| 71 |
+
# DataLoader
|
| 72 |
+
dataloader = create_hf_dataloader(
|
| 73 |
+
dataset_name="data/ultrachat_200k",
|
| 74 |
+
tokenizer=tokenizer,
|
| 75 |
+
max_seq_len=config.max_seq_len,
|
| 76 |
+
batch_size=args.batch_size,
|
| 77 |
+
split="train_sft",
|
| 78 |
+
max_samples=args.max_samples
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
optimizer = torch.optim.AdamW(model.parameters(), lr=args.lr, betas=(0.9, 0.95), weight_decay=0.01)
|
| 82 |
+
criterion = nn.CrossEntropyLoss(ignore_index=tokenizer.pad_id)
|
| 83 |
+
|
| 84 |
+
print(f"\nStarting Nova 2.0 MoE Pre-Training on AMD ROCm GPU across {args.max_samples:,} samples...", flush=True)
|
| 85 |
+
|
| 86 |
+
for epoch in range(args.epochs):
|
| 87 |
+
model.train()
|
| 88 |
+
total_loss = 0.0
|
| 89 |
+
total_aux = 0.0
|
| 90 |
+
steps_per_epoch = len(dataloader)
|
| 91 |
+
|
| 92 |
+
for step, (b_inp, b_tgt) in enumerate(dataloader):
|
| 93 |
+
b_inp = b_inp.to(config.device)
|
| 94 |
+
b_tgt = b_tgt.to(config.device)
|
| 95 |
+
|
| 96 |
+
# Synthetic multi-modal vision features (16 patches x 768 dim) for 20% of batches
|
| 97 |
+
pixel_inp = torch.randn(b_inp.shape[0], 16, 768, device=config.device) if random.random() < 0.2 else None
|
| 98 |
+
|
| 99 |
+
optimizer.zero_grad()
|
| 100 |
+
with torch.amp.autocast("cuda", enabled=(config.device == "cuda"), dtype=config.get_torch_dtype()):
|
| 101 |
+
logits, _, _, aux_loss = model(b_inp, pixel_features=pixel_inp)
|
| 102 |
+
|
| 103 |
+
if logits.shape[1] > b_tgt.shape[1]:
|
| 104 |
+
target_len = b_tgt.shape[1]
|
| 105 |
+
logits_text = logits[:, -target_len:, :]
|
| 106 |
+
else:
|
| 107 |
+
logits_text = logits
|
| 108 |
+
|
| 109 |
+
loss_lm = criterion(logits_text.reshape(-1, config.vocab_size), b_tgt.reshape(-1))
|
| 110 |
+
total_step_loss = loss_lm + 0.01 * aux_loss
|
| 111 |
+
|
| 112 |
+
total_step_loss.backward()
|
| 113 |
+
torch.nn.utils.clip_grad_norm_(model.parameters(), max_norm=1.0)
|
| 114 |
+
optimizer.step()
|
| 115 |
+
|
| 116 |
+
total_loss += loss_lm.item()
|
| 117 |
+
total_aux += aux_loss.item()
|
| 118 |
+
|
| 119 |
+
if (step + 1) % 10 == 0 or (step + 1) == steps_per_epoch:
|
| 120 |
+
print(f"MoE Epoch {epoch+1}/{args.epochs} [{step+1}/{steps_per_epoch}] β LM Loss: {loss_lm.item():.4f} | Aux Loss: {aux_loss.item():.2f}", flush=True)
|
| 121 |
+
|
| 122 |
+
avg_lm_loss = total_loss / steps_per_epoch
|
| 123 |
+
print(f"MoE Epoch {epoch+1}/{args.epochs} Complete β Avg LM Loss: {avg_lm_loss:.4f}\n", flush=True)
|
| 124 |
+
|
| 125 |
+
# Save Checkpoint
|
| 126 |
+
ckpt_path = f"checkpoints/nova2_moe_epoch_{epoch+1}.pt"
|
| 127 |
+
torch.save({"model_state": model.state_dict(), "config": config}, ckpt_path)
|
| 128 |
+
|
| 129 |
+
final_path = "checkpoints/nova2_moe_multidomain.pt"
|
| 130 |
+
torch.save({"model_state": model.state_dict(), "config": config}, final_path)
|
| 131 |
+
print(f"π Nova 2.0 MoE Pre-Training Complete! Model saved to '{final_path}'.", flush=True)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
if __name__ == "__main__":
|
| 135 |
+
main()
|