Views
No views yet
1# Clone and setup
2git clone https://github.com/vukrosic/build-and-release-your-own-llm
3cd build-and-release-your-own-llm
4python setup.py # Installs requirements and creates .env file1# Install dependencies
2pip install -r requirements.txt
3
4# Run inference with my pre-trained model
5python inference.pyvukrosic/blueberry-11# Install dependencies
2pip install -r requirements.txt
3
4# Start training (takes ~20 minutes on GPU)
5python train_llm.py
6
7# Use your trained model
8python inference.pycheckpoints/ and you can resume training anytime.1# 1. Copy environment template
2cp .env.example .env
3
4# 2. Edit .env file:
5# HF_REPO_NAME=your-username/your-model-name
6# HF_TOKEN=hf_your_token_here
7# PUSH_TO_HUB=true
8
9# 3. Train (uploads automatically)
10python train_llm.py├── train_llm.py # Training script with Muon optimizer
├── inference.py # Text generation and model loading
├── upload_to_hf.py # Upload checkpoints to Hugging Face
├── example_usage.py # Example workflow script
├── setup.py # Easy setup script
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
└── README.md # This filetrain_llm.py:1@dataclass
2class ModelConfig:
3 d_model: int = 512 # Bigger model (was 384)
4 n_layers: int = 8 # More layers (was 6)
5 max_steps: int = 5000 # Train longer for better results (20000)train_llm.py:1# Replace this line:
2dataset = load_dataset("HuggingFaceTB/smollm-corpus", "cosmopedia-v2", split="train", streaming=True)
3
4# With your dataset:
5dataset = load_dataset("your-dataset-name", split="train", streaming=True)1batch_size: int = 16 # Smaller = less memory
2gradient_accumulation_steps: int = 8 # Larger = same effective batch sizeTraining: 67%|██████▋ | 20000/30000 [12:34<06:15, 26.6it/s, loss=1.234, acc=0.876, ppl=3.4, lr=8.5e-03]Prompt: The future of AI is
Generated text: The future of AI is bright and full of possibilities. Machine learning algorithms continue to evolve...1# In train_llm.py, reduce batch size:
2batch_size: int = 12 # or even 81python train_llm.py # Wait for it to complete
2python inference.py # Now this will work.env filecheckpoints/ directory:checkpoints/
├── checkpoint_step_5000/
│ ├── model.pt # Model weights and optimizer state
│ ├── config.json # Model configuration
│ └── tokenizer files # Tokenizer configuration
├── checkpoint_step_10000/
└── checkpoint_step_15000/1# Set your Hugging Face token
2export HF_TOKEN="hf_your_token_here"
3
4# List available checkpoints
5python upload_to_hf.py --list
6
7# Upload latest checkpoint
8python upload_to_hf.py --repo-name username/my-awesome-model
9
10# Upload specific checkpoint
11python upload_to_hf.py --repo-name username/my-model --checkpoint checkpoints/checkpoint_step_10000
12
13# Create private repository
14python upload_to_hf.py --repo-name username/my-model --private1# Run the complete example
2python example_usage.py
3
4# Or step by step:
5python train_llm.py # Train model (saves checkpoints)
6python upload_to_hf.py --list # See available checkpoints
7python upload_to_hf.py --repo-name username/model # Upload to HFnvidia-smi to check memory usagesave_every in ModelConfig for different intervals