viraj.kothari commited on
Commit ·
ff47b6f
1
Parent(s): 04480e3
switch to docker space for huggingface deployment
Browse files- Dockerfile +8 -2
- README.md +16 -46
- serve.py +3 -2
Dockerfile
CHANGED
|
@@ -14,8 +14,14 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 14 |
COPY . .
|
| 15 |
|
| 16 |
# Create necessary directories
|
| 17 |
-
RUN mkdir -p checkpoints export data/shards tokenizer
|
|
|
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
CMD ["python", "serve.py"]
|
|
|
|
| 14 |
COPY . .
|
| 15 |
|
| 16 |
# Create necessary directories
|
| 17 |
+
RUN mkdir -p checkpoints export data/shards tokenizer \
|
| 18 |
+
finetune/checkpoints frontend
|
| 19 |
|
| 20 |
+
# HuggingFace requires port 7860
|
| 21 |
+
EXPOSE 7860
|
| 22 |
+
|
| 23 |
+
# HuggingFace runs as non-root user 1000
|
| 24 |
+
RUN useradd -m -u 1000 user
|
| 25 |
+
USER user
|
| 26 |
|
| 27 |
CMD ["python", "serve.py"]
|
README.md
CHANGED
|
@@ -1,56 +1,30 @@
|
|
|
|
|
| 1 |
---
|
| 2 |
title: My LLM
|
| 3 |
emoji: 🧠
|
| 4 |
colorFrom: green
|
| 5 |
colorTo: black
|
| 6 |
-
sdk:
|
|
|
|
| 7 |
pinned: true
|
| 8 |
---
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
### 1. Install dependencies
|
| 13 |
-
```bash
|
| 14 |
-
python -m venv env
|
| 15 |
-
source env/bin/activate
|
| 16 |
-
pip install -r requirements.txt
|
| 17 |
-
```
|
| 18 |
-
|
| 19 |
-
### 2. Train tokenizer
|
| 20 |
-
```bash
|
| 21 |
-
python tokenizer/train_tokenizer.py
|
| 22 |
-
```
|
| 23 |
-
|
| 24 |
-
### 3. Prepare data
|
| 25 |
-
```bash
|
| 26 |
-
python data/prepare.py
|
| 27 |
-
```
|
| 28 |
-
|
| 29 |
-
### 4. Train model
|
| 30 |
-
```bash
|
| 31 |
-
# CPU
|
| 32 |
-
python train.py
|
| 33 |
|
| 34 |
-
|
| 35 |
-
python train.py --device cuda
|
| 36 |
-
```
|
| 37 |
|
| 38 |
-
##
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
| 43 |
|
| 44 |
-
##
|
| 45 |
-
```bash
|
| 46 |
-
python serve.py
|
| 47 |
-
# Open http://localhost:3001
|
| 48 |
-
```
|
| 49 |
-
|
| 50 |
-
### 7. Docker deployment
|
| 51 |
-
```bash
|
| 52 |
docker compose up --build
|
| 53 |
-
|
|
|
|
| 54 |
|
| 55 |
## Training Results
|
| 56 |
| Steps | Loss | Perplexity |
|
|
@@ -58,9 +32,5 @@ docker compose up --build
|
|
| 58 |
| 500 | 5.81 | 335 |
|
| 59 |
|
| 60 |
## Tech Stack
|
| 61 |
-
|
| 62 |
-
- SentencePiece
|
| 63 |
-
- FastAPI + Uvicorn
|
| 64 |
-
- HuggingFace Datasets
|
| 65 |
-
- Docker
|
| 66 |
EOF
|
|
|
|
| 1 |
+
cat > README.md << 'EOF'
|
| 2 |
---
|
| 3 |
title: My LLM
|
| 4 |
emoji: 🧠
|
| 5 |
colorFrom: green
|
| 6 |
colorTo: black
|
| 7 |
+
sdk: docker
|
| 8 |
+
app_port: 7860
|
| 9 |
pinned: true
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# My LLM — Built from Scratch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
A complete, production-grade LLM built entirely from scratch.
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
## Architecture
|
| 17 |
+
- Decoder-only transformer (GPT-style)
|
| 18 |
+
- 35M parameters
|
| 19 |
+
- Grouped Query Attention (GQA)
|
| 20 |
+
- SwiGLU FFN + RoPE + RMSNorm
|
| 21 |
+
- Int8 quantization for CPU inference
|
| 22 |
|
| 23 |
+
## Quickstart
|
| 24 |
+
\`\`\`bash
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
docker compose up --build
|
| 26 |
+
# Open http://localhost:3001
|
| 27 |
+
\`\`\`
|
| 28 |
|
| 29 |
## Training Results
|
| 30 |
| Steps | Loss | Perplexity |
|
|
|
|
| 32 |
| 500 | 5.81 | 335 |
|
| 33 |
|
| 34 |
## Tech Stack
|
| 35 |
+
PyTorch · SentencePiece · FastAPI · Docker · HuggingFace
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
EOF
|
serve.py
CHANGED
|
@@ -129,7 +129,7 @@ def root():
|
|
| 129 |
|
| 130 |
@app.get("/health")
|
| 131 |
def health():
|
| 132 |
-
return {"status": "ok", "model": "my-llm", "params": model.num_params()}
|
| 133 |
|
| 134 |
|
| 135 |
@app.post("/generate", response_model=GenerateResponse)
|
|
@@ -174,4 +174,5 @@ def chat(req: GenerateRequest):
|
|
| 174 |
return generate(req)
|
| 175 |
|
| 176 |
if __name__ == "__main__":
|
| 177 |
-
|
|
|
|
|
|
| 129 |
|
| 130 |
@app.get("/health")
|
| 131 |
def health():
|
| 132 |
+
return {"status": "ok" if model is not None else "no model loaded", "model": "my-llm", "params": model.num_params() if model is not None else 0}
|
| 133 |
|
| 134 |
|
| 135 |
@app.post("/generate", response_model=GenerateResponse)
|
|
|
|
| 174 |
return generate(req)
|
| 175 |
|
| 176 |
if __name__ == "__main__":
|
| 177 |
+
port = int(os.environ.get("PORT", 7860))
|
| 178 |
+
uvicorn.run("serve:app", host="0.0.0.0", port=port, reload=False)
|