Replicating work by David Ng https://dnhkng.github.io/posts/rys/
This repo contains a Jupyter notebook (vllm_cookbook.ipynb) for running NVIDIA Nemotron with vLLM, plus utilities for repeating decoder layers during inference and benchmarking (KL/NLL probes and objective MCQ accuracy on GPQA, ARC-Challenge, HellaSwag).
Open the notebook in Colab
vllm_cookbook.ipynb to Google Drive (or clone this repo), then open it with Open in Colab (right‑click → Open with → Google Colaboratory), orvllm_cookbook.ipynb.Runtime and GPU
gpt2 examples.Install dependencies
%pip install for vLLM, PyTorch, and Transformers. Let them finish before running model or benchmark cells.!pip install -q torch transformers datasets
What to run
forward_repeating_layers, generate_batched_with_repeated_layers, and _get_decoder_stack.gpt2 by default.gpt2 unless you pass a different model_name or an existing model/tokenizer.Using your own model (e.g. Nemotron)
AutoModelForCausalLM.from_pretrained(..., trust_remote_code=True) and AutoTokenizer.from_pretrained(...)), then pass model= and tokenizer= into benchmark_repeated_layers_quality(...) and run_objective_mcq_benchmarks(...) so the notebook does not re-download the model.DINOv3 ViT-B/16 layer-repeat test (test_dinov3_layer_repeat.py)
pip install torch transformers pillow
Use transformers>=5.3 so DINOv3ViTModel is available. If the checkpoint is gated, log in (huggingface-cli login or Colab secrets).python test_dinov3_layer_repeat.py
DINOV3_ALLOW_CPU=1 to override (slow). Import forward_vit_control, benchmark_repeated_layers_embedding_drift, etc. from a Colab cell if you prefer not to use __main__.DINOv3 objective benchmarks (dinov3_colab_benchmarks.py)
knn): Scene Parse 150 patch k-NN — build a labeled feature bank with the control forward (frozen ViT), then classify val patches by neighbor vote using control vs repeat embeddings. No weights trained (only inference).linear_probe): trains a small linear readout on frozen patch features (still not fine-tuning DINOv3). Use --dense-mode linear_probe if you want that SSL-style linear probe.pip install torch transformers datasets pillow numpy
pip install git+https://github.com/yberreby/dinov3-in1k-probes.git
Requires transformers>=5.3. First run downloads Imagenette + Scene Parse 150.python dinov3_colab_benchmarks.py (same CUDA guard; --skip-global / --skip-dense for one track; --dense-mode knn or linear_probe).pip install torch transformers datasets
(Add vllm and version pins from the notebook if you run the full vLLM/Nemotron stack.)python test_small_model.py
This runs the repeated-layer quality benchmark on gpt2 and prints KL/NLL metrics.test_dinov3_layer_repeat.py refuses to run the default benchmark without CUDA.dinov3_colab_benchmarks.py (Imagenette + IN1k linear probe; Scene Parse 150 patch mIoU).Script: nemotron_layer_grid_sweep.py
NVFP4 checkpoints are not supported here (plain AutoModelForCausalLM.from_pretrained fails: packed weight shapes vs full Linear dims). Use BF16 or FP8 Nemotron ids for this script; use vLLM for NVFP4 per the NVIDIA model README.
Smoke test only (checks forward_control_no_repeat, forward_repeating_layers, and one benchmark_repeated_layers_quality call):
python nemotron_layer_grid_sweep.py --model-id nvidia/NVIDIA-Nemotron-3-Super-120B-A12B-BF16 --trust-remote-code --smoke-only
Use --model-id gpt2 for a fast local check.
Full grid over all (i, j) with 0 <= i <= j < n_layers (writes JSONL: first line meta, then one result per pair):
python nemotron_layer_grid_sweep.py \
--model-id nvidia/NVIDIA-Nemotron-3-Super-120B-A12B-BF16 \
--trust-remote-code \
--output layer_grid_results.jsonl \
--extra-passes 1
HF_TOKEN (or HUGGING_FACE_HUB_TOKEN) if the model is gated.device_map="auto" (multi-GPU friendly).--short-prompts: one short prompt (much faster on huge models).--limit-pairs N: stop after N pairs (debugging).Google Colab: upload or clone the repo, install deps (pip install torch transformers), then run the same commands in a cell with !python nemotron_layer_grid_sweep.py .... Use an H100 / A100 runtime and enough disk for the checkpoint; G4 is usually too small for 120B weights.
For Nemotron 120B-class runs you typically need multi-GPU, large disk for the HF cache, and BF16/FP8 (not NVFP4) on this Transformers path.
Full guide: docs/HOSTING.md — pick enterprise vs marketplace vs 8×GPU box, provision disk, then operational checklist.
Verify GPUs and disk before from_pretrained:
python nemotron_layer_grid_sweep.py --check-env
python nemotron_layer_grid_sweep.py --check-env --min-gpus 4
Then smoke → chunked sweep: --smoke-only, then --short-prompts with --limit-pairs (see Nemotron layer grid sweep section above).
10 commits
Jupyter Notebook
66.3%
Python
33.7%
Replicating work by David Ng https://dnhkng.github.io/posts/rys/
This repo contains a Jupyter notebook (vllm_cookbook.ipynb) for running NVIDIA Nemotron with vLLM, plus utilities for repeating decoder layers during inference and benchmarking (KL/NLL probes and objective MCQ accuracy on GPQA, ARC-Challenge, HellaSwag).
Open the notebook in Colab
vllm_cookbook.ipynb to Google Drive (or clone this repo), then open it with Open in Colab (right‑click → Open with → Google Colaboratory), orvllm_cookbook.ipynb.Runtime and GPU
gpt2 examples.Install dependencies
%pip install for vLLM, PyTorch, and Transformers. Let them finish before running model or benchmark cells.!pip install -q torch transformers datasets
What to run
forward_repeating_layers, generate_batched_with_repeated_layers, and _get_decoder_stack.gpt2 by default.gpt2 unless you pass a different model_name or an existing model/tokenizer.Using your own model (e.g. Nemotron)
AutoModelForCausalLM.from_pretrained(..., trust_remote_code=True) and AutoTokenizer.from_pretrained(...)), then pass model= and tokenizer= into benchmark_repeated_layers_quality(...) and run_objective_mcq_benchmarks(...) so the notebook does not re-download the model.DINOv3 ViT-B/16 layer-repeat test (test_dinov3_layer_repeat.py)
pip install torch transformers pillow
Use transformers>=5.3 so DINOv3ViTModel is available. If the checkpoint is gated, log in (huggingface-cli login or Colab secrets).python test_dinov3_layer_repeat.py
DINOV3_ALLOW_CPU=1 to override (slow). Import forward_vit_control, benchmark_repeated_layers_embedding_drift, etc. from a Colab cell if you prefer not to use __main__.DINOv3 objective benchmarks (dinov3_colab_benchmarks.py)
knn): Scene Parse 150 patch k-NN — build a labeled feature bank with the control forward (frozen ViT), then classify val patches by neighbor vote using control vs repeat embeddings. No weights trained (only inference).linear_probe): trains a small linear readout on frozen patch features (still not fine-tuning DINOv3). Use --dense-mode linear_probe if you want that SSL-style linear probe.pip install torch transformers datasets pillow numpy
pip install git+https://github.com/yberreby/dinov3-in1k-probes.git
Requires transformers>=5.3. First run downloads Imagenette + Scene Parse 150.python dinov3_colab_benchmarks.py (same CUDA guard; --skip-global / --skip-dense for one track; --dense-mode knn or linear_probe).pip install torch transformers datasets
(Add vllm and version pins from the notebook if you run the full vLLM/Nemotron stack.)python test_small_model.py
This runs the repeated-layer quality benchmark on gpt2 and prints KL/NLL metrics.test_dinov3_layer_repeat.py refuses to run the default benchmark without CUDA.dinov3_colab_benchmarks.py (Imagenette + IN1k linear probe; Scene Parse 150 patch mIoU).Script: nemotron_layer_grid_sweep.py
NVFP4 checkpoints are not supported here (plain AutoModelForCausalLM.from_pretrained fails: packed weight shapes vs full Linear dims). Use BF16 or FP8 Nemotron ids for this script; use vLLM for NVFP4 per the NVIDIA model README.
Smoke test only (checks forward_control_no_repeat, forward_repeating_layers, and one benchmark_repeated_layers_quality call):
python nemotron_layer_grid_sweep.py --model-id nvidia/NVIDIA-Nemotron-3-Super-120B-A12B-BF16 --trust-remote-code --smoke-only
Use --model-id gpt2 for a fast local check.
Full grid over all (i, j) with 0 <= i <= j < n_layers (writes JSONL: first line meta, then one result per pair):
python nemotron_layer_grid_sweep.py \
--model-id nvidia/NVIDIA-Nemotron-3-Super-120B-A12B-BF16 \
--trust-remote-code \
--output layer_grid_results.jsonl \
--extra-passes 1
HF_TOKEN (or HUGGING_FACE_HUB_TOKEN) if the model is gated.device_map="auto" (multi-GPU friendly).--short-prompts: one short prompt (much faster on huge models).--limit-pairs N: stop after N pairs (debugging).Google Colab: upload or clone the repo, install deps (pip install torch transformers), then run the same commands in a cell with !python nemotron_layer_grid_sweep.py .... Use an H100 / A100 runtime and enough disk for the checkpoint; G4 is usually too small for 120B weights.
For Nemotron 120B-class runs you typically need multi-GPU, large disk for the HF cache, and BF16/FP8 (not NVFP4) on this Transformers path.
Full guide: docs/HOSTING.md — pick enterprise vs marketplace vs 8×GPU box, provision disk, then operational checklist.
Verify GPUs and disk before from_pretrained:
python nemotron_layer_grid_sweep.py --check-env
python nemotron_layer_grid_sweep.py --check-env --min-gpus 4
Then smoke → chunked sweep: --smoke-only, then --short-prompts with --limit-pairs (see Nemotron layer grid sweep section above).
10 commits
Jupyter Notebook
66.3%
Python
33.7%