neuralbroker commited on
Commit
11f64d8
·
verified ·
1 Parent(s): 2a2cc3c

Update clean backend-only project docs and eval

Browse files
Files changed (1) hide show
  1. docs/PRODUCTION_RUNBOOK.md +178 -0
docs/PRODUCTION_RUNBOOK.md ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # BlitzKode Production Runbook
2
+
3
+ This runbook captures the operational path for serving BlitzKode as a local or self-hosted coding assistant.
4
+
5
+ ## 1. Release artifacts
6
+
7
+ Expected production artifacts:
8
+
9
+ - `blitzkode.gguf` — local GGUF model mounted into the container at `/app/blitzkode.gguf`.
10
+ - Docker image built from `Dockerfile` — includes `server.py` and Python dependencies only.
11
+ - Optional HuggingFace repos:
12
+ - `neuralbroker/blitzkode` — GGUF distribution repo.
13
+ - `neuralbroker/blitzkode-1.5b-lora` — 1.5B adapter repo.
14
+ - `neuralbroker/blitzkode-lora-0.5b` — 0.5B adapter repo.
15
+
16
+ Do not commit model weights, checkpoints, `.env` files, or HuggingFace tokens to git.
17
+
18
+ ## 2. Required environment
19
+
20
+ Minimum runtime:
21
+
22
+ - Python 3.11+ when running directly.
23
+ - Docker 24+ when running in containers.
24
+ - 4 GB+ RAM for the Q8_0 1.5B GGUF artifact.
25
+ - Optional NVIDIA container toolkit for GPU offload.
26
+
27
+ Key server variables:
28
+
29
+ | Variable | Production guidance |
30
+ |---|---|
31
+ | `BLITZKODE_MODEL_PATH` | Set to `/app/blitzkode.gguf` in Docker or an absolute local path outside Docker. |
32
+ | `BLITZKODE_PRELOAD_MODEL` | Use `true` for production so startup fails fast if the model cannot load. |
33
+ | `BLITZKODE_API_KEY` | Set a strong bearer token for any network-accessible deployment. |
34
+ | `BLITZKODE_CORS_ORIGINS` | Restrict to trusted API client origins instead of `*`. |
35
+ | `BLITZKODE_RATE_LIMIT` | Keep `true` unless running behind another trusted limiter. |
36
+ | `BLITZKODE_RATE_LIMIT_MAX` | Tune based on expected users and hardware. |
37
+ | `BLITZKODE_WEB_SEARCH` | Set `false` for fully offline operation; keep `true` for research mode. |
38
+ | `BLITZKODE_GPU_LAYERS` | `0` for CPU only, `-1` for all possible layers on GPU, or tune gradually. |
39
+ | `BLITZKODE_N_CTX` | Start with `2048`; increase to `4096` or higher only if memory allows. |
40
+ | `BLITZKODE_BATCH` / `BLITZKODE_UBATCH` | Start with `256` / `128`; increase only after latency and memory checks. |
41
+ | `BLITZKODE_PROMPT_CACHE` | Keep `true` for repeated system/history prefixes if supported by the installed `llama-cpp-python`. |
42
+
43
+ ## 3. Pre-deployment validation
44
+
45
+ Run these checks before tagging or deploying a release:
46
+
47
+ ```bash
48
+ python -m pytest tests/ -v
49
+ python -m ruff check .
50
+ python -m mypy server.py --ignore-missing-imports
51
+ docker build -t blitzkode:ci .
52
+ ```
53
+
54
+ For CI smoke tests without the real model, start the container with `BLITZKODE_PRELOAD_MODEL=false` and verify `/health` returns HTTP 200.
55
+
56
+ ## 4. CPU Docker deployment
57
+
58
+ Place `blitzkode.gguf` next to `docker-compose.yml`, then run:
59
+
60
+ ```bash
61
+ docker compose up --build -d
62
+ ```
63
+
64
+ The default compose service mounts the model read-only into `/app/blitzkode.gguf` and exposes the app on `http://localhost:7860`.
65
+
66
+ Check service state:
67
+
68
+ ```bash
69
+ docker compose ps
70
+ docker compose logs --tail=100 blitzkode
71
+ curl -sf http://localhost:7860/health
72
+ curl -sf http://localhost:7860/info
73
+ ```
74
+
75
+ A healthy deployment should report:
76
+
77
+ - `status` is `healthy` when the model file exists.
78
+ - `model_exists` is `true`.
79
+ - `last_error` is empty or `null`.
80
+ - `batch`, `ubatch`, and thread settings match the intended deployment profile.
81
+
82
+ ## 5. GPU Docker deployment
83
+
84
+ Prerequisites:
85
+
86
+ 1. NVIDIA driver installed on the host.
87
+ 2. `nvidia-container-toolkit` installed.
88
+ 3. Docker configured for the NVIDIA runtime.
89
+ 4. A `llama-cpp-python` build with compatible GPU acceleration.
90
+
91
+ Start the GPU profile:
92
+
93
+ ```bash
94
+ BLITZKODE_GPU_LAYERS=35 docker compose --profile gpu up --build -d
95
+ ```
96
+
97
+ If startup fails or inference crashes, lower `BLITZKODE_GPU_LAYERS` and restart. Use `0` to force CPU-only fallback.
98
+
99
+ ## 6. Direct local deployment
100
+
101
+ For non-container operation:
102
+
103
+ ```bash
104
+ pip install -r requirements.txt
105
+ BLITZKODE_MODEL_PATH=blitzkode.gguf BLITZKODE_PRELOAD_MODEL=true python server.py
106
+ ```
107
+
108
+ On Windows shells, set environment variables using the shell-specific syntax before running `python server.py`.
109
+
110
+ ## 7. Health checks and smoke tests
111
+
112
+ Recommended checks after each deployment:
113
+
114
+ ```bash
115
+ curl -sf http://localhost:7860/health
116
+ curl -sf http://localhost:7860/info
117
+ curl -sf -X POST http://localhost:7860/generate \
118
+ -H "Content-Type: application/json" \
119
+ -d '{"prompt":"Return a short Python hello-world function.","max_tokens":64}'
120
+ ```
121
+
122
+ If `BLITZKODE_API_KEY` is configured, include `Authorization: Bearer <token>` on protected requests.
123
+
124
+ ## 8. Rollback plan
125
+
126
+ Rollback should be artifact-based and fast:
127
+
128
+ 1. Keep the last known-good Docker image tag available locally or in the registry.
129
+ 2. Keep the last known-good `blitzkode.gguf` artifact available outside the container.
130
+ 3. Stop the current service.
131
+ 4. Restore the previous image tag and/or previous model file.
132
+ 5. Start the service and run the health checks from section 7.
133
+
134
+ Example container rollback flow:
135
+
136
+ ```bash
137
+ docker compose down
138
+ docker tag blitzkode:previous blitzkode:latest
139
+ docker compose up -d
140
+ curl -sf http://localhost:7860/health
141
+ ```
142
+
143
+ ## 9. HuggingFace publishing
144
+
145
+ Use a token only through environment variables or CI secrets:
146
+
147
+ ```bash
148
+ HF_TOKEN=hf_xxx python scripts/push_all_to_hub.py
149
+ ```
150
+
151
+ Before publishing, confirm:
152
+
153
+ - `blitzkode.gguf` exists and loads locally.
154
+ - Adapter directories contain `adapter_config.json` and adapter weights.
155
+ - `MODEL_CARD.md`, `README.md`, and `datasets/MANIFEST.md` match the artifact versions.
156
+ - The token has write access to the intended repos.
157
+
158
+ Never paste real tokens into documentation, committed scripts, or issue comments.
159
+
160
+ ## 10. Common failure modes
161
+
162
+ | Symptom | Likely cause | Fix |
163
+ |---|---|---|
164
+ | `/health` returns `degraded` | Model file missing from configured path | Mount or copy `blitzkode.gguf`; verify `BLITZKODE_MODEL_PATH`. |
165
+ | Startup hangs while loading | Large context/batch or slow CPU disk load | Reduce `BLITZKODE_N_CTX` / `BLITZKODE_BATCH`, check disk and RAM. |
166
+ | Container exits on first request | llama.cpp cannot load model | Verify GGUF file integrity and llama-cpp-python compatibility. |
167
+ | Browser cannot call API | CORS origin mismatch | Set `BLITZKODE_CORS_ORIGINS` to the deployed UI origin. |
168
+ | HTTP 401 | Missing or wrong bearer token | Send `Authorization: Bearer <BLITZKODE_API_KEY>`. |
169
+ | HTTP 429 | Rate limit exceeded | Increase `BLITZKODE_RATE_LIMIT_MAX` or add an upstream queue/limit policy. |
170
+ | Research mode fails | Web search disabled or network blocked | Set `BLITZKODE_WEB_SEARCH=true` and verify outbound HTTP access. |
171
+
172
+ ## 11. Operational notes
173
+
174
+ - Treat generated code as assistant output, not an automatically trusted patch.
175
+ - Prefer `/generate/research` for current APIs or documentation-sensitive questions.
176
+ - Keep logs free of prompts if prompts may contain private code or secrets.
177
+ - Rotate `BLITZKODE_API_KEY` and HuggingFace tokens regularly.
178
+ - Re-run the full validation suite after changing dependencies, model artifacts, or Docker base images.