Upload nemotron_35_cpt_steps.txt with huggingface_hub
Browse files- nemotron_35_cpt_steps.txt +120 -0
nemotron_35_cpt_steps.txt
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
mkdir -p /home/ubuntu/data /home/ubuntu/data/sft /home/ubuntu/models /home/ubuntu/checkpoints /home/ubuntu/workspace/configs
|
| 2 |
+
|
| 3 |
+
docker pull nvcr.io/nvidia/nemo-automodel:26.08
|
| 4 |
+
|
| 5 |
+
docker run --gpus all -it --rm \
|
| 6 |
+
--shm-size=32g \
|
| 7 |
+
--ulimit memlock=-1 --ulimit stack=67108864 \
|
| 8 |
+
-v /home/ubuntu/data:/data \
|
| 9 |
+
-v /home/ubuntu/models:/models \
|
| 10 |
+
-v /home/ubuntu/checkpoints:/checkpoints \
|
| 11 |
+
-v /home/ubuntu/hf_cache:/root/.cache/huggingface \
|
| 12 |
+
-v /home/ubuntu/workspace/configs:/configs \
|
| 13 |
+
nvcr.io/nvidia/nemo-automodel:26.08 /bin/bash
|
| 14 |
+
|
| 15 |
+
hf download nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-Base-BF16 \
|
| 16 |
+
--local-dir /home/ubuntu/models/nemotron35-lightning-base
|
| 17 |
+
|
| 18 |
+
# Run from inside the Automodel repo / container
|
| 19 |
+
python tools/preprocess_megatron_dataset.py \
|
| 20 |
+
--input "/data/source/Con_jsonl_new.jsonl" \
|
| 21 |
+
--json-keys text \
|
| 22 |
+
--output-prefix kyc_us_new \
|
| 23 |
+
--output-path /data/megatron_nemotron/ \
|
| 24 |
+
--workers 32 \
|
| 25 |
+
--pretrained-model-name-or-path nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-Base-BF16 \
|
| 26 |
+
--append-eod
|
| 27 |
+
|
| 28 |
+
python -c "import nemo_automodel; print(nemo_automodel.__version__)"
|
| 29 |
+
python -c "import torch; print(torch.__version__, torch.cuda.device_count())"
|
| 30 |
+
python -c "import mamba_ssm, causal_conv1d; print('mamba deps OK')"
|
| 31 |
+
nvidia-smi
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
python - <<'PY'
|
| 35 |
+
import torch
|
| 36 |
+
from nemo_automodel import NeMoAutoModelForCausalLM
|
| 37 |
+
from transformers import AutoTokenizer
|
| 38 |
+
|
| 39 |
+
PATH = "/models/nemotron35-lightning-base"
|
| 40 |
+
tok = AutoTokenizer.from_pretrained(PATH, trust_remote_code=True)
|
| 41 |
+
model = NeMoAutoModelForCausalLM.from_pretrained(
|
| 42 |
+
PATH, dtype=torch.bfloat16, device_map="auto", trust_remote_code=True,
|
| 43 |
+
)
|
| 44 |
+
print("params:", sum(p.numel() for p in model.parameters())/1e9, "B")
|
| 45 |
+
print("peak mem GiB:", torch.cuda.max_memory_allocated()/2**30)
|
| 46 |
+
PY
|
| 47 |
+
|
| 48 |
+
================================================================================
|
| 49 |
+
|
| 50 |
+
torchrun --nproc-per-node=1 \
|
| 51 |
+
/opt/Automodel/examples/llm_pretrain/pretrain.py \
|
| 52 |
+
--config /configs/nemotron35_lightning_cpt.yaml
|
| 53 |
+
|
| 54 |
+
================================================================================
|
| 55 |
+
=================================================================================
|
| 56 |
+
#Try this first
|
| 57 |
+
python - <<'PY'
|
| 58 |
+
import torch
|
| 59 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 60 |
+
from peft import PeftModel
|
| 61 |
+
|
| 62 |
+
BASE = "/models/nemotron3-nano-base"
|
| 63 |
+
ADAPTER = "/checkpoints/cpt/epoch_0_step_5000/model"
|
| 64 |
+
OUT = "/models/nemotron3-nano-cpt-merged"
|
| 65 |
+
|
| 66 |
+
tok = AutoTokenizer.from_pretrained(BASE, trust_remote_code=True)
|
| 67 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 68 |
+
BASE, dtype=torch.bfloat16, trust_remote_code=True, device_map="cpu",
|
| 69 |
+
)
|
| 70 |
+
model = PeftModel.from_pretrained(model, ADAPTER)
|
| 71 |
+
model = model.merge_and_unload()
|
| 72 |
+
model.save_pretrained(OUT, safe_serialization=True)
|
| 73 |
+
tok.save_pretrained(OUT)
|
| 74 |
+
print("merged ->", OUT)
|
| 75 |
+
PY
|
| 76 |
+
|
| 77 |
+
---------------------------------------------------------------------------
|
| 78 |
+
|
| 79 |
+
python - <<'PY'
|
| 80 |
+
import os
|
| 81 |
+
import glob
|
| 82 |
+
import shutil
|
| 83 |
+
import torch
|
| 84 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 85 |
+
from peft import PeftModel
|
| 86 |
+
from safetensors.torch import save_file
|
| 87 |
+
|
| 88 |
+
BASE = "/models/nemotron35-lightning-base"
|
| 89 |
+
ADAPTER = "/checkpoints/cpt/epoch_0_step_1999/model"
|
| 90 |
+
OUT = "/models/nemotron35-lightning-cpt-merged"
|
| 91 |
+
|
| 92 |
+
os.makedirs(OUT, exist_ok=True)
|
| 93 |
+
|
| 94 |
+
print("1/4 Loading tokenizer and base model...")
|
| 95 |
+
tok = AutoTokenizer.from_pretrained(BASE, trust_remote_code=True)
|
| 96 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 97 |
+
BASE, dtype=torch.bfloat16, trust_remote_code=True, device_map="cpu"
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
print(f"2/4 Merging adapter from {ADAPTER}...")
|
| 101 |
+
model = PeftModel.from_pretrained(model, ADAPTER)
|
| 102 |
+
model = model.merge_and_unload()
|
| 103 |
+
|
| 104 |
+
print("3/4 Saving config and custom dynamic module (.py) files...")
|
| 105 |
+
model.config.save_pretrained(OUT)
|
| 106 |
+
tok.save_pretrained(OUT)
|
| 107 |
+
|
| 108 |
+
# Copy dynamic python code files required for trust_remote_code=True
|
| 109 |
+
for file_path in glob.glob(os.path.join(BASE, "*.py")):
|
| 110 |
+
shutil.copy(file_path, OUT)
|
| 111 |
+
|
| 112 |
+
print("4/4 Saving consolidated safetensors weights...")
|
| 113 |
+
save_file(model.state_dict(), os.path.join(OUT, "model.safetensors"))
|
| 114 |
+
|
| 115 |
+
print("=" * 60)
|
| 116 |
+
print(f"SUCCESS: Merged model saved to -> {OUT}")
|
| 117 |
+
print("=" * 60)
|
| 118 |
+
PY
|
| 119 |
+
|
| 120 |
+
=====================================================================================
|