Skip to content

Commit d2721d2

Browse files
committed
Initial commit
0 parents  commit d2721d2

12 files changed

+1801
-0
lines changed

.gitignore

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
.hypothesis/
50+
.pytest_cache/
51+
52+
# Translations
53+
*.mo
54+
*.pot
55+
56+
# Django stuff:
57+
*.log
58+
local_settings.py
59+
db.sqlite3
60+
61+
# Flask stuff:
62+
instance/
63+
.webassets-cache
64+
65+
# Scrapy stuff:
66+
.scrapy
67+
68+
# Sphinx documentation
69+
docs/_build/
70+
71+
# PyBuilder
72+
target/
73+
74+
# Jupyter Notebook
75+
.ipynb_checkpoints
76+
77+
# IPython
78+
profile_default/
79+
ipython_config.py
80+
81+
# pyenv
82+
.python-version
83+
84+
# celery beat schedule file
85+
celerybeat-schedule
86+
87+
# SageMath parsed files
88+
*.sage.py
89+
90+
# Environments
91+
.env
92+
.venv
93+
env/*
94+
venv/
95+
ENV/
96+
env.bak/
97+
venv.bak/
98+
99+
# Spyder project settings
100+
.spyderproject
101+
.spyproject
102+
103+
# Rope project settings
104+
.ropeproject
105+
106+
# mkdocs documentation
107+
/site
108+
109+
# mypy
110+
.mypy_cache/
111+
.dmypy.json
112+
dmypy.json
113+
114+
# Pyre type checker
115+
.pyre/
116+
117+
# PyCharm
118+
.idea/

.pre-commit-config.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v2.5.0
4+
hooks:
5+
- id: trailing-whitespace
6+
types: [file, text]
7+
- id: end-of-file-fixer
8+
types: [python]
9+
- id: mixed-line-ending
10+
types: [python]
11+
args: ["--fix=lf"]
12+
13+
- repo: https://github.com/psf/black
14+
rev: 24.3.0
15+
hooks:
16+
- id: black
17+
types: [python]
18+
19+
- repo: https://github.com/pycqa/isort
20+
rev: 5.13.2
21+
hooks:
22+
- id: isort

MANIFEST.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include llama3/py.typed
2+
global-exclude __pycache__
3+
global-exclude *.py[co]

NOTICE

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
This project incorporates components from the projects listed below. The original copyright notices are set forth below.
2+
3+
#############################################################################################################################################################
4+
5+
1. Code in {llama3/llama3.py, main.py} adapted from:
6+
https://github.com/meta-llama/llama3
7+
8+
META LLAMA 3 COMMUNITY LICENSE AGREEMENT
9+
10+
Meta Llama 3 is licensed under the Meta Llama 3 Community License, Copyright © Meta Platforms, Inc. All Rights Reserved.
11+
12+
#############################################################################################################################################################

README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# LLaMA 3
2+
3+
A single-file implementation of [LLaMA 3](https://arxiv.org/abs/2407.21783), with support for jitting, KV caching and prompting.
4+
5+
The original implementation can be found at https://github.com/meta-llama/llama3.
6+
7+
---------------------------------------------------------------------------------------------------------
8+
9+
## 🛠️️ Installation
10+
11+
### Using Pip
12+
13+
First of all, install [Python 3.8 or later](https://www.python.org). Open a terminal and run:
14+
15+
```bash
16+
pip install git+https://github.com/lucadellalib/llama3@main#egg=llama3[all]
17+
```
18+
19+
### From Source
20+
21+
First of all, install [Python 3.8 or later](https://www.python.org).
22+
Clone or download and extract the repository, navigate to `<path-to-repository>`, open a terminal and run:
23+
24+
```bash
25+
# Install the package locally in editable mode
26+
pip install -e .[all]
27+
```
28+
29+
---------------------------------------------------------------------------------------------------------
30+
31+
## ▶️ Quickstart
32+
33+
### Importing the Model in Your Own Script
34+
35+
```python
36+
import torch
37+
from llama3 import LlamaDecoder
38+
39+
B, H, K = 3, 512, 30
40+
model = LlamaDecoder(K)
41+
print(model)
42+
43+
# Process 50 timesteps
44+
input = torch.randn(B, 50, H)
45+
output, state = model(input)
46+
print(output.shape)
47+
48+
# Process 2 additional timesteps
49+
input = torch.randn(B, 2, H)
50+
output, state = model(input, state=state)
51+
print(output.shape)
52+
53+
# JIT the model
54+
model_jit = model.jit()
55+
output_jit, state_jit = model_jit(input)
56+
print(output.shape)
57+
```
58+
59+
### Inference Example With Pretrained Checkpoint
60+
61+
First of all, download the model weights and tokenizer (pretrained variant, e.g. Llama3.2-1B). Check the official
62+
website for instructions on how to [download the models](https://github.com/meta-llama/llama3#download).
63+
64+
Navigate to `<path-to-repository>`, open a terminal and run:
65+
66+
```bash
67+
python main.py --checkpoint_path <path-to-checkpoint>
68+
```
69+
70+
It is recommended to run this script on a machine with at least 1 GPU.
71+
72+
---------------------------------------------------------------------------------------------------------
73+
74+
## 📧 Contact
75+
76+
77+
78+
---------------------------------------------------------------------------------------------------------

llama3/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from llama3.llama3 import *
2+
from llama3.version import VERSION as __version__

0 commit comments

Comments
 (0)