PyTorch-llama2 implementation from first-principles.
inference.py— example inference script for loading model weights and running generationmodel.py,tokenizer(or similar) — helper modules for model loading and tokenization
Install dependencies (adjust versions or use requirements.txt in this folder if provided):
pip install --upgrade pip
pip install torch torchvision transformers accelerate sentencepiece safetensors tqdmPlace model weights
- Create a folder for weights in this directory (example):
mkdir -p ./weights/llama
# copy or download your model files into ./weights/llama- Ensure you follow the license and usage terms of the model provider before downloading or redistributing weights.
The inference.py script demonstrates loading the model and running generation. An example invocation (adjust flags to your script):
python inference.py- Download or convert weights into
weights/llama. - Install dependencies in a virtual environment.
- Run
inference.pyor open any example notebook to test generation.
- Python 3.8+
- PyTorch (match CUDA version if using GPU)
- transformers, accelerate, sentencepiece, safetensors (optional)
- other utilities used by scripts in this folder (check
requirements.txt)
pytorch-llama (implementation reference): https://github.com/hkproj/pytorch-llama