Optimize for Tokens/GPU Throughput
Optimize for Tokens/GPU Throughput
Optimize for Tokens/GPU Throughput
About
Learn how to use the NeMo Platform Customizer to create a LoRA (Low-Rank Adaptation) customization job optimized for higher tokens/GPU throughput and lower runtime.
In this tutorial, you will:
- Fine-tune meta-llama/Llama-3.2-1B-Instruct on the SQuAD dataset using LoRA, with sequence packing enabled for one run and disabled for another.
- Compare training runtime, GPU utilization, and memory allocation between the two runs.
- Verify that validation loss remains comparable, confirming that sequence packing improves throughput without sacrificing model quality.
Note: While this tutorial demonstrates sequence packing with LoRA, the optimization is also available for all_weights (full) SFT customization jobs.
Prerequisites
Before starting this tutorial, ensure you have:
- Completed the Quickstart to install and deploy NeMo Platform locally
- Installed the Python SDK (PyPI wrapper:
pip install "nemo-platform[all]"; source checkout: runmake bootstrapfrom the repository root)
Quick Start
1. Initialize SDK
The SDK needs to know your NeMo Platform server URL. By default, http://localhost:8080 is used in accordance with the Quickstart guide. If NeMo Platform is running at a custom location, you can override the URL by setting the NMP_BASE_URL environment variable:
2. Create Dataset FileSet and Upload Training Data
Install additional dependencies if they are not installed in your Python environment.
The cell below automatically detects your environment and uses:
uv pip installif you’re in a uv-managed virtual environmentpip installotherwise
Required packages:
datasets- Download the public rajpurkar/squad datasetpandas- Compare job results in table formatmatplotlib- Plot live training metrics (loss curves, GPU utilization)nvidia-ml-py- Collect GPU VRAM and compute utilization metrics during training
Download rajpurkar/squad Dataset
SQuAD (Stanford Question Answering Dataset) is a reading comprehension dataset consisting of questions posed on Wikipedia articles, where the answer is a segment of text from the corresponding passage.
3. Secrets Setup
If you plan to use NGC or HuggingFace models, you will need to configure authentication:
- NGC models (
ngc://URIs): Requires NGC API key - HuggingFace models (
hf://URIs): Requires HF token for gated/private models
Configure these as secrets in your platform. Refer to Managing Secrets for detailed instructions.
Get your credentials to access base models:
- NGC API Key (Setup → Generate API Key)
- HuggingFace Token (Create token with Read access)
Quick Setup Example
This tutorial uses the meta-llama/Llama-3.2-1B-Instruct model from HuggingFace. Ensure that you have sufficient permissions to download the model. If you cannot access the files on the meta-llama/Llama-3.2-1B-Instruct Hugging Face page, request access.
HuggingFace Authentication:
- For gated models (Llama, Gemma), you must provide a HuggingFace token via the
token_secretparameter - Get your token from HuggingFace Settings (requires Read access)
- Accept the model’s terms on the HuggingFace model page before using it. Example: meta-llama/Llama-3.2-1B-Instruct
- For public models, you can omit the
token_secretparameter when creating a fileset for the model in the next step.
4. Create Base Model FileSet
Create a fileset pointing to the meta-llama/Llama-3.2-1B-Instruct model on HuggingFace. This step creates a pointer to the model on Hugging Face and does not download it. The model is downloaded at job creation time.
Note: for public models, you can omit the token_secret parameter when creating a model fileset.
5. Create LoRA Job with Sequence Packing
Create a LoRA customization job with sequence packing enabled via AutomodelJobInput (batch.sequence_packing=True).
6. Track Finetuning Progress
A training job contains multiple steps:
- Model and dataset downloading
- Finetuning where LoRA adapter weights are trained
- Creating a fileset entry for the finetuned model
- Finetuned weights uploading
The elapsed time printed below reflects progress of the entire job. We compare the time taken by the finetuning step for both jobs in the last section of this tutorial.
Define Helper Functions
Monitor the Job Until Completion
The cell below polls the job status every 10 seconds and renders a live dashboard with validation loss, GPU VRAM usage, and GPU utilization charts. The charts appear empty at first while the model and dataset download; training metrics and GPU activity populate after the finetuning step begins.
Note: This is additional code. You can also use the Weights & Biases or MLflow integrations.
7. Create LoRA Job without Sequence Packing
Create a second Automodel LoRA job with batch.sequence_packing=False for comparison.
8. Track Finetuning Progress for Job without Sequence Packing
9. Compare Results
- Time to complete training should be significantly lower for the job that used sequence packing.
- The expected validation loss for both jobs should be similar.
- Sequence packed version should have a higher GPU utilization and higher GPU Memory Allocation.
Examples of Validation Loss
The expected validation loss curves should match closely for both jobs.

Sequence packed version should complete significantly faster.

GPU Utilization
Sequence packed version should have a higher GPU utilization.

GPU Memory Allocation
Sequence packed version should have a higher GPU Memory Allocation.
