Text Generation
Transformers
PEFT
llama
disaster-management
emergency-response
humanitarian-ai
multilingual
fine-tuned
qlora
lora
llama3
conversational
4-bit precision
bitsandbytes
Instructions to use drdeveloper88/WorldDisasterLM-8B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use drdeveloper88/WorldDisasterLM-8B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="drdeveloper88/WorldDisasterLM-8B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("drdeveloper88/WorldDisasterLM-8B") model = AutoModelForCausalLM.from_pretrained("drdeveloper88/WorldDisasterLM-8B", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - PEFT
How to use drdeveloper88/WorldDisasterLM-8B with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use drdeveloper88/WorldDisasterLM-8B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "drdeveloper88/WorldDisasterLM-8B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "drdeveloper88/WorldDisasterLM-8B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/drdeveloper88/WorldDisasterLM-8B
- SGLang
How to use drdeveloper88/WorldDisasterLM-8B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "drdeveloper88/WorldDisasterLM-8B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "drdeveloper88/WorldDisasterLM-8B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "drdeveloper88/WorldDisasterLM-8B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "drdeveloper88/WorldDisasterLM-8B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use drdeveloper88/WorldDisasterLM-8B with Docker Model Runner:
docker model run hf.co/drdeveloper88/WorldDisasterLM-8B
Commit ·
4b93901
1
Parent(s): 5e069b0
Sync: correct languages (en/ne/es/fr/ar/hi/te/zh/ja/ko/pt), updated README, full source code
Browse files- README.md +235 -135
- scripts/sync_to_hf.py +380 -0
- scripts/write_hf_configs.py +246 -0
- tokenizer_config.json +1 -1
- training_args.json +22 -8
README.md
CHANGED
|
@@ -2,26 +2,29 @@
|
|
| 2 |
language:
|
| 3 |
- en
|
| 4 |
- ne
|
| 5 |
-
- hi
|
| 6 |
-
- ar
|
| 7 |
-
- fr
|
| 8 |
- es
|
| 9 |
-
-
|
| 10 |
-
-
|
| 11 |
-
-
|
|
|
|
| 12 |
- zh
|
| 13 |
-
-
|
|
|
|
|
|
|
| 14 |
license: llama3
|
| 15 |
library_name: transformers
|
|
|
|
| 16 |
tags:
|
| 17 |
-
- disaster-
|
| 18 |
-
- emergency-
|
| 19 |
- humanitarian-ai
|
| 20 |
- multilingual
|
| 21 |
- fine-tuned
|
| 22 |
- qlora
|
|
|
|
|
|
|
| 23 |
- llama3
|
| 24 |
-
|
| 25 |
model-index:
|
| 26 |
- name: WorldDisasterLM-8B
|
| 27 |
results: []
|
|
@@ -29,24 +32,25 @@ model-index:
|
|
| 29 |
|
| 30 |
# WorldDisasterLM-8B
|
| 31 |
|
| 32 |
-
> **Open-source AI foundation model for global disaster intelligence, emergency response, and humanitarian aid — supporting 11 languages including Nepali.**
|
| 33 |
|
| 34 |
[](https://python.org)
|
| 35 |
[](https://ai.meta.com/llama/license/)
|
| 36 |
-
[![
|
|
|
|
| 37 |
|
| 38 |
---
|
| 39 |
|
| 40 |
-
##
|
| 41 |
|
| 42 |
**WorldDisasterLM-8B** is a production-grade, domain-specialized large language model fine-tuned on top of `meta-llama/Llama-3.1-8B-Instruct` using **QLoRA** (4-bit NF4 quantization, LoRA r=16). It is purpose-built to assist:
|
| 43 |
|
| 44 |
-
- **Emergency responders** — real-time disaster action guidance
|
| 45 |
-
- **Humanitarian aid workers** — resource allocation and triage support
|
| 46 |
-
- **Government agencies** — risk assessment and crisis intelligence
|
| 47 |
-
- **Global communities** — multilingual disaster preparedness in 11 languages
|
| 48 |
|
| 49 |
-
Training data is collected live from six free public APIs: ReliefWeb, USGS Earthquake, GDACS, NOAA Weather, OpenFEMA, and WHO — with automated QA amplification generating 8 instruction variants per disaster record.
|
| 50 |
|
| 51 |
---
|
| 52 |
|
|
@@ -56,192 +60,288 @@ Training data is collected live from six free public APIs: ReliefWeb, USGS Earth
|
|
| 56 |
|---|---|
|
| 57 |
| **Base model** | `meta-llama/Llama-3.1-8B-Instruct` |
|
| 58 |
| **Fine-tuning** | QLoRA — 4-bit NF4, LoRA r=16, all attn+MLP projectors |
|
| 59 |
-
| **Languages** | 11: English, Nepali
|
| 60 |
-
| **
|
| 61 |
-
| **
|
| 62 |
-
| **
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
---
|
| 65 |
|
| 66 |
-
##
|
| 67 |
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
---
|
| 71 |
|
| 72 |
-
##
|
| 73 |
|
| 74 |
-
|
| 75 |
-
WorldDisasterLM-8B/
|
| 76 |
-
├── backend/ # FastAPI REST API (production server)
|
| 77 |
-
│ └── app/
|
| 78 |
-
│ ├── main.py # App entry point, /v1/* routes
|
| 79 |
-
│ ├── routers/ # chat, risk, incidents endpoints
|
| 80 |
-
│ └── services/ # inference_service.py
|
| 81 |
-
├── worlddisasterlm/ # Core model package
|
| 82 |
-
│ ├── config.py # SUPPORTED_LANGUAGES, model config
|
| 83 |
-
│ ├── model.py # QLoRA model wrapper
|
| 84 |
-
│ └── trainer.py # Training pipeline
|
| 85 |
-
├── hf_space/ # Gradio Space app (self-contained)
|
| 86 |
-
│ ├── app.py
|
| 87 |
-
│ └── requirements.txt
|
| 88 |
-
├── scripts/ # Training, eval, dataset scripts
|
| 89 |
-
│ ├── train_production.py
|
| 90 |
-
│ └── generate_dataset.py
|
| 91 |
-
├── tests/ # 9 passing unit/integration tests
|
| 92 |
-
├── train.py # Main training entry point
|
| 93 |
-
├── evaluate.py # Evaluation harness
|
| 94 |
-
├── inference.py # Direct inference script
|
| 95 |
-
├── dataset_builder.py # Data pipeline
|
| 96 |
-
├── Dockerfile # Production container
|
| 97 |
-
├── docker-compose.yml # Multi-service setup
|
| 98 |
-
└── requirements.txt # Python dependencies
|
| 99 |
-
```
|
| 100 |
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
```bash
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
pip install -r requirements.txt
|
| 111 |
```
|
| 112 |
|
| 113 |
-
###
|
| 114 |
|
| 115 |
```bash
|
| 116 |
-
uvicorn backend.app.main:app --
|
| 117 |
```
|
| 118 |
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
```bash
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
```
|
| 126 |
|
| 127 |
-
|
|
|
|
|
|
|
| 128 |
|
| 129 |
```bash
|
| 130 |
-
|
| 131 |
-
-H "Content-Type: application/json" \
|
| 132 |
-
-d '{"region": "Kathmandu", "hazard": "earthquake", "vulnerability": 0.8, "exposure": 0.9}'
|
| 133 |
```
|
| 134 |
|
| 135 |
-
|
|
|
|
|
|
|
| 136 |
|
| 137 |
```bash
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
```
|
| 140 |
|
| 141 |
---
|
| 142 |
|
| 143 |
-
##
|
| 144 |
|
| 145 |
-
|
| 146 |
-
|------|----------|--------|
|
| 147 |
-
| `en` | English | Latin |
|
| 148 |
-
| `ne` | Nepali | Devanagari |
|
| 149 |
-
| `hi` | Hindi | Devanagari |
|
| 150 |
-
| `ar` | Arabic | Arabic |
|
| 151 |
-
| `fr` | French | Latin |
|
| 152 |
-
| `es` | Spanish | Latin |
|
| 153 |
-
| `sw` | Swahili | Latin |
|
| 154 |
-
| `id` | Indonesian | Latin |
|
| 155 |
-
| `pt` | Portuguese | Latin |
|
| 156 |
-
| `zh` | Chinese | CJK |
|
| 157 |
-
| `bn` | Bengali | Bengali |
|
| 158 |
|
| 159 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
-
##
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
| `/v1/incidents/classify` | POST | Classify incident type |
|
| 169 |
|
| 170 |
-
|
| 171 |
|
| 172 |
-
|
|
|
|
|
|
|
| 173 |
|
| 174 |
-
|
| 175 |
|
| 176 |
```bash
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
--output_dir ./checkpoints
|
| 183 |
```
|
| 184 |
|
| 185 |
-
|
| 186 |
|
| 187 |
```bash
|
| 188 |
-
python scripts/
|
|
|
|
|
|
|
| 189 |
```
|
| 190 |
|
| 191 |
---
|
| 192 |
|
| 193 |
-
##
|
| 194 |
|
| 195 |
-
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
```
|
| 198 |
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
---
|
| 202 |
|
| 203 |
-
##
|
| 204 |
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
-
|
| 209 |
-
- Healthcare organizations in crisis zones
|
| 210 |
-
- Community preparedness programs
|
| 211 |
|
| 212 |
-
#
|
|
|
|
|
|
|
| 213 |
|
| 214 |
-
|
| 215 |
-
- Medical diagnosis or clinical decisions
|
| 216 |
-
- Financial or legal advice
|
| 217 |
-
- Any purpose that replaces trained human emergency professionals
|
| 218 |
|
| 219 |
---
|
| 220 |
|
| 221 |
-
## Safety
|
| 222 |
|
| 223 |
-
-
|
| 224 |
-
-
|
| 225 |
-
-
|
| 226 |
-
-
|
| 227 |
-
-
|
| 228 |
|
| 229 |
---
|
| 230 |
|
| 231 |
-
##
|
| 232 |
|
| 233 |
-
``
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
year={2025},
|
| 238 |
-
publisher={HuggingFace},
|
| 239 |
-
url={https://huggingface.co/drdeveloper88/WorldDisasterLM-8B}
|
| 240 |
-
}
|
| 241 |
-
```
|
| 242 |
|
| 243 |
---
|
| 244 |
|
| 245 |
## License
|
| 246 |
|
| 247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
language:
|
| 3 |
- en
|
| 4 |
- ne
|
|
|
|
|
|
|
|
|
|
| 5 |
- es
|
| 6 |
+
- fr
|
| 7 |
+
- ar
|
| 8 |
+
- hi
|
| 9 |
+
- te
|
| 10 |
- zh
|
| 11 |
+
- ja
|
| 12 |
+
- ko
|
| 13 |
+
- pt
|
| 14 |
license: llama3
|
| 15 |
library_name: transformers
|
| 16 |
+
base_model: meta-llama/Llama-3.1-8B-Instruct
|
| 17 |
tags:
|
| 18 |
+
- disaster-management
|
| 19 |
+
- emergency-response
|
| 20 |
- humanitarian-ai
|
| 21 |
- multilingual
|
| 22 |
- fine-tuned
|
| 23 |
- qlora
|
| 24 |
+
- lora
|
| 25 |
+
- peft
|
| 26 |
- llama3
|
| 27 |
+
pipeline_tag: text-generation
|
| 28 |
model-index:
|
| 29 |
- name: WorldDisasterLM-8B
|
| 30 |
results: []
|
|
|
|
| 32 |
|
| 33 |
# WorldDisasterLM-8B
|
| 34 |
|
| 35 |
+
> **Open-source AI foundation model for global disaster intelligence, emergency response, and humanitarian aid — supporting 11 languages including Nepali (नेपाली).**
|
| 36 |
|
| 37 |
[](https://python.org)
|
| 38 |
[](https://ai.meta.com/llama/license/)
|
| 39 |
+
[](https://huggingface.co)
|
| 40 |
+
[]()
|
| 41 |
|
| 42 |
---
|
| 43 |
|
| 44 |
+
## What is WorldDisasterLM-8B?
|
| 45 |
|
| 46 |
**WorldDisasterLM-8B** is a production-grade, domain-specialized large language model fine-tuned on top of `meta-llama/Llama-3.1-8B-Instruct` using **QLoRA** (4-bit NF4 quantization, LoRA r=16). It is purpose-built to assist:
|
| 47 |
|
| 48 |
+
- 🌍 **Emergency responders** — real-time disaster action guidance
|
| 49 |
+
- 🏥 **Humanitarian aid workers** — resource allocation and triage support
|
| 50 |
+
- 🏛️ **Government agencies** — risk assessment and crisis intelligence
|
| 51 |
+
- 🌐 **Global communities** — multilingual disaster preparedness in 11 languages
|
| 52 |
|
| 53 |
+
Training data is collected **live** from six free public APIs: ReliefWeb, USGS Earthquake, GDACS, NOAA Weather, OpenFEMA, and WHO — with automated QA amplification generating 8 instruction variants per disaster record.
|
| 54 |
|
| 55 |
---
|
| 56 |
|
|
|
|
| 60 |
|---|---|
|
| 61 |
| **Base model** | `meta-llama/Llama-3.1-8B-Instruct` |
|
| 62 |
| **Fine-tuning** | QLoRA — 4-bit NF4, LoRA r=16, all attn+MLP projectors |
|
| 63 |
+
| **Languages** | 11: English, Nepali (नेपाली), Spanish, French, Arabic, Hindi, Telugu, Chinese, Japanese, Korean, Portuguese |
|
| 64 |
+
| **Data sources** | ReliefWeb, USGS, GDACS, NOAA, OpenFEMA, WHO |
|
| 65 |
+
| **Dataset size** | 88+ live records → 711+ instruction samples per run |
|
| 66 |
+
| **API** | FastAPI REST + Server-Sent Events streaming |
|
| 67 |
+
| **Frontend** | React 18 + Vite disaster analytics dashboard |
|
| 68 |
+
| **Export** | GGUF (llama.cpp) + ONNX formats |
|
| 69 |
+
| **HuggingFace** | Auto-push via `scripts/push_to_hub.py` |
|
| 70 |
|
| 71 |
---
|
| 72 |
|
| 73 |
+
## Supported Languages
|
| 74 |
|
| 75 |
+
| Language | Code | Script |
|
| 76 |
+
|---|---|---|
|
| 77 |
+
| English | `en` | Latin |
|
| 78 |
+
| **Nepali** | `ne` | **Devanagari (नेपाली)** |
|
| 79 |
+
| Spanish | `es` | Latin |
|
| 80 |
+
| French | `fr` | Latin |
|
| 81 |
+
| Arabic | `ar` | Arabic |
|
| 82 |
+
| Hindi | `hi` | Devanagari |
|
| 83 |
+
| Telugu | `te` | Telugu |
|
| 84 |
+
| Chinese | `zh` | Hanzi |
|
| 85 |
+
| Japanese | `ja` | Kanji/Hiragana |
|
| 86 |
+
| Korean | `ko` | Hangul |
|
| 87 |
+
| Portuguese | `pt` | Latin |
|
| 88 |
|
| 89 |
---
|
| 90 |
|
| 91 |
+
## Quick Start
|
| 92 |
|
| 93 |
+
### 1. Clone and install
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
+
```bash
|
| 96 |
+
git clone <your-repo-url> worlddisasterllm
|
| 97 |
+
cd worlddisasterllm
|
| 98 |
+
python -m venv .venv
|
| 99 |
|
| 100 |
+
# Windows
|
| 101 |
+
.venv\Scripts\activate
|
| 102 |
+
# macOS/Linux
|
| 103 |
+
source .venv/bin/activate
|
| 104 |
+
|
| 105 |
+
pip install -r requirements.txt
|
| 106 |
+
```
|
| 107 |
|
| 108 |
+
> **Windows note:** If your path has spaces, always set:
|
| 109 |
+
> ```powershell
|
| 110 |
+
> $env:PYTHONPATH = "C:\path\to\worlddisasterllm"
|
| 111 |
+
> ```
|
| 112 |
+
|
| 113 |
+
### 2. Configure environment
|
| 114 |
|
| 115 |
```bash
|
| 116 |
+
cp .env.example .env
|
| 117 |
+
# Add HF_TOKEN for HuggingFace publishing (optional)
|
|
|
|
| 118 |
```
|
| 119 |
|
| 120 |
+
### 3. Run the API backend
|
| 121 |
|
| 122 |
```bash
|
| 123 |
+
uvicorn backend.app.main:app --reload --port 8000
|
| 124 |
```
|
| 125 |
|
| 126 |
+
API available at: `http://localhost:8000`
|
| 127 |
+
Interactive docs: `http://localhost:8000/docs`
|
| 128 |
+
|
| 129 |
+
### 4. Run the React dashboard
|
| 130 |
|
| 131 |
```bash
|
| 132 |
+
cd frontend
|
| 133 |
+
npm install
|
| 134 |
+
npm run dev
|
| 135 |
```
|
| 136 |
|
| 137 |
+
Dashboard at: `http://localhost:5173`
|
| 138 |
+
|
| 139 |
+
### 5. Run the Gradio demo
|
| 140 |
|
| 141 |
```bash
|
| 142 |
+
python app.py
|
|
|
|
|
|
|
| 143 |
```
|
| 144 |
|
| 145 |
+
Demo at: `http://localhost:7860`
|
| 146 |
+
|
| 147 |
+
### 6. Run CLI inference
|
| 148 |
|
| 149 |
```bash
|
| 150 |
+
# English
|
| 151 |
+
python inference.py --prompt "What to do during a flood?" --language English --region Nepal
|
| 152 |
+
|
| 153 |
+
# Nepali
|
| 154 |
+
python inference.py --prompt "भूकम्पको बेला के गर्ने?" --language Nepali --region Nepal
|
| 155 |
```
|
| 156 |
|
| 157 |
---
|
| 158 |
|
| 159 |
+
## Training Pipeline
|
| 160 |
|
| 161 |
+
### Step 1 — Collect live data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
+
```bash
|
| 164 |
+
python scripts/collect_data.py
|
| 165 |
+
# Collects from: ReliefWeb, USGS, GDACS, NOAA, OpenFEMA, WHO
|
| 166 |
+
# Output: data/processed/instruction_dataset.jsonl
|
| 167 |
+
```
|
| 168 |
|
| 169 |
+
### Step 2 — Fine-tune with QLoRA
|
| 170 |
|
| 171 |
+
```bash
|
| 172 |
+
python train.py --output checkpoints/worlddisasterlm-8b-qlora
|
| 173 |
+
# Requires GPU (A100/V100 recommended)
|
| 174 |
+
# Uses: 4-bit NF4 quantization + LoRA r=16 + SFTTrainer
|
| 175 |
+
```
|
|
|
|
| 176 |
|
| 177 |
+
### Step 3 — Evaluate
|
| 178 |
|
| 179 |
+
```bash
|
| 180 |
+
python evaluate.py
|
| 181 |
+
```
|
| 182 |
|
| 183 |
+
### Step 4 — Push to HuggingFace
|
| 184 |
|
| 185 |
```bash
|
| 186 |
+
export HF_TOKEN=hf_xxxx # or $env:HF_TOKEN on Windows
|
| 187 |
+
python scripts/push_to_hub.py \
|
| 188 |
+
--adapter checkpoints/worlddisasterlm-8b-qlora \
|
| 189 |
+
--base-model meta-llama/Llama-3.1-8B-Instruct \
|
| 190 |
+
--repo-id YourUsername/WorldDisasterLM-8B
|
|
|
|
| 191 |
```
|
| 192 |
|
| 193 |
+
### Step 5 — Export to GGUF (for llama.cpp / Ollama)
|
| 194 |
|
| 195 |
```bash
|
| 196 |
+
python scripts/export_gguf.py \
|
| 197 |
+
--model-path checkpoints/worlddisasterlm-8b-qlora \
|
| 198 |
+
--output-path artifacts/worlddisasterlm-8b.gguf
|
| 199 |
```
|
| 200 |
|
| 201 |
---
|
| 202 |
|
| 203 |
+
## API Reference
|
| 204 |
|
| 205 |
+
### Health check
|
| 206 |
+
```
|
| 207 |
+
GET /health
|
| 208 |
+
→ { "status": "ok", "model": "WorldDisasterLM-8B" }
|
| 209 |
+
```
|
| 210 |
+
|
| 211 |
+
### Disaster chat
|
| 212 |
+
```
|
| 213 |
+
POST /v1/chat
|
| 214 |
+
{
|
| 215 |
+
"messages": [{"role": "user", "content": "What to do during earthquake?"}],
|
| 216 |
+
"language": "Nepali",
|
| 217 |
+
"region": "Nepal"
|
| 218 |
+
}
|
| 219 |
+
→ { "answer": "[WorldDisasterLM-8B | नेपाली | Nepal] ...", "confidence": 0.74, ... }
|
| 220 |
+
```
|
| 221 |
+
|
| 222 |
+
### Streaming chat
|
| 223 |
+
```
|
| 224 |
+
POST /v1/chat/stream (Server-Sent Events)
|
| 225 |
+
```
|
| 226 |
+
|
| 227 |
+
### Risk scoring
|
| 228 |
+
```
|
| 229 |
+
POST /v1/risk/score
|
| 230 |
+
{ "region": "South Asia", "hazard_type": "flood", "vulnerability_index": 0.74, "exposure_index": 0.81 }
|
| 231 |
+
→ { "risk_score": ..., "risk_level": "High", "recommendation": "..." }
|
| 232 |
+
```
|
| 233 |
+
|
| 234 |
+
### Incident classification
|
| 235 |
+
```
|
| 236 |
+
POST /v1/incidents/classify
|
| 237 |
+
{ "text": "Magnitude 7.1 earthquake near coastal city. Hospitals overloaded." }
|
| 238 |
+
→ { "incident_type": "earthquake", "severity": "critical", ... }
|
| 239 |
```
|
| 240 |
|
| 241 |
+
---
|
| 242 |
+
|
| 243 |
+
## Repository Structure
|
| 244 |
+
|
| 245 |
+
```
|
| 246 |
+
worlddisasterlm/
|
| 247 |
+
├── backend/ FastAPI backend
|
| 248 |
+
│ └── app/
|
| 249 |
+
│ ├── main.py API entrypoint
|
| 250 |
+
│ ├── services/
|
| 251 |
+
│ │ ├── inference_service.py Core response generation (multilingual)
|
| 252 |
+
│ │ └── risk_engine.py Risk scoring engine
|
| 253 |
+
│ ├── guardrails/
|
| 254 |
+
│ │ └── safety.py Prompt safety filters
|
| 255 |
+
│ └── models/schemas.py Pydantic v2 request/response models
|
| 256 |
+
├── worlddisasterlm/ Core ML package
|
| 257 |
+
│ ├── config.py SUPPORTED_LANGUAGES, PipelineConfig
|
| 258 |
+
│ ├── data/
|
| 259 |
+
│ │ ├── collectors/ 6 live API data collectors
|
| 260 |
+
│ │ ├── etl.py Extract-Transform-Load pipeline
|
| 261 |
+
│ │ ├── qa_generator.py 8-variant QA amplification
|
| 262 |
+
│ │ ├── scenario_builder.py Multilingual disaster scenarios
|
| 263 |
+
│ │ └── processors.py JSONL dataset builder
|
| 264 |
+
│ ├── training/
|
| 265 |
+
│ │ ├── train_qlora.py Production QLoRA training (SFTTrainer)
|
| 266 |
+
│ │ └── chat_format.py Llama 3.1 chat template
|
| 267 |
+
│ ├── evaluation/
|
| 268 |
+
│ │ ├── metrics.py Task + safety metrics
|
| 269 |
+
│ │ └── multilingual_eval.py 11-language coverage scoring
|
| 270 |
+
│ └── optimization/
|
| 271 |
+
│ ├── export_gguf.py GGUF export (llama.cpp)
|
| 272 |
+
│ └── export_onnx.py ONNX export
|
| 273 |
+
├── frontend/ React 18 + Vite dashboard
|
| 274 |
+
│ └── src/App.jsx Language selector, chat, analytics, monitoring
|
| 275 |
+
├── scripts/
|
| 276 |
+
│ ├── collect_data.py Live data collection orchestrator
|
| 277 |
+
│ ├── push_to_hub.py HuggingFace Hub publisher
|
| 278 |
+
│ ├── export_gguf.py GGUF CLI wrapper
|
| 279 |
+
│ └── export_onnx.py ONNX CLI wrapper
|
| 280 |
+
├── tests/
|
| 281 |
+
│ ├── test_api.py FastAPI integration tests (incl. Nepali)
|
| 282 |
+
│ ├── test_dataset_builder.py ETL + Nepali language tests
|
| 283 |
+
│ └── test_risk_engine.py Risk scoring tests
|
| 284 |
+
├── inference.py CLI inference entrypoint
|
| 285 |
+
├── train.py Training entrypoint
|
| 286 |
+
├── evaluate.py Evaluation entrypoint
|
| 287 |
+
├── app.py Gradio demo
|
| 288 |
+
├── dataset_builder.py Dataset build entrypoint
|
| 289 |
+
├── Dockerfile API container
|
| 290 |
+
├── docker-compose.yml Full stack (API + frontend + MLflow)
|
| 291 |
+
└── pyproject.toml Project metadata + pytest config
|
| 292 |
+
```
|
| 293 |
|
| 294 |
---
|
| 295 |
|
| 296 |
+
## Running Tests
|
| 297 |
|
| 298 |
+
```bash
|
| 299 |
+
# Windows
|
| 300 |
+
$env:PYTHONPATH = "C:\path\to\worlddisasterllm"
|
| 301 |
+
python -m pytest tests/ -v
|
|
|
|
|
|
|
| 302 |
|
| 303 |
+
# macOS/Linux
|
| 304 |
+
PYTHONPATH=. pytest tests/ -v
|
| 305 |
+
```
|
| 306 |
|
| 307 |
+
Expected output: **9 passed** — including Nepali language tests.
|
|
|
|
|
|
|
|
|
|
| 308 |
|
| 309 |
---
|
| 310 |
|
| 311 |
+
## Safety and Responsible AI
|
| 312 |
|
| 313 |
+
- Prompt-level guardrails block unsafe instructions
|
| 314 |
+
- Output confidence scoring with human-review flags
|
| 315 |
+
- Emergency disclaimers on all life-safety guidance
|
| 316 |
+
- Hallucination heuristics with citation anchoring
|
| 317 |
+
- Human-in-the-loop escalation for critical incidents
|
| 318 |
|
| 319 |
---
|
| 320 |
|
| 321 |
+
## HuggingFace Publishing
|
| 322 |
|
| 323 |
+
The model is published as **`WorldDisasterLM-8B`** on HuggingFace Hub with:
|
| 324 |
+
- Merged LoRA adapters (production-ready weights)
|
| 325 |
+
- Model card with 11-language tags (`en`, `ne`, `es`, `fr`, `ar`, `hi`, `te`, `zh`, `ja`, `ko`, `pt`)
|
| 326 |
+
- GGUF variant for llama.cpp / Ollama compatibility
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
|
| 328 |
---
|
| 329 |
|
| 330 |
## License
|
| 331 |
|
| 332 |
+
Base model: [Llama 3 Community License](https://ai.meta.com/llama/license/) (Meta).
|
| 333 |
+
This fine-tuning code and dataset pipeline: **Apache 2.0**.
|
| 334 |
+
|
| 335 |
+
---
|
| 336 |
+
|
| 337 |
+
## Acknowledgements
|
| 338 |
+
|
| 339 |
+
- [Meta AI — Llama 3.1](https://ai.meta.com/blog/meta-llama-3/)
|
| 340 |
+
- [ReliefWeb API](https://reliefweb.int/help/api)
|
| 341 |
+
- [USGS Earthquake Hazards Program](https://earthquake.usgs.gov/fdsnws/event/1/)
|
| 342 |
+
- [GDACS Global Disaster Alert](https://www.gdacs.org)
|
| 343 |
+
- [NOAA Weather.gov API](https://api.weather.gov)
|
| 344 |
+
- [OpenFEMA API](https://www.fema.gov/about/openfema)
|
| 345 |
+
- [WHO RSS Feeds](https://www.who.int/rss-feeds)
|
| 346 |
+
- [NDRRMA Nepal — राष्ट्रिय विपद् जोखिम न्यूनीकरण तथा व्यवस्थापन प्राधिकरण](https://www.ndrrma.gov.np)
|
| 347 |
+
|
scripts/sync_to_hf.py
ADDED
|
@@ -0,0 +1,380 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Fully automated sync of WorldDisasterLM-8B project to HuggingFace model repo.
|
| 3 |
+
Reads the real project README, updates all configs to match, commits and pushes.
|
| 4 |
+
|
| 5 |
+
Usage:
|
| 6 |
+
python scripts/sync_to_hf.py
|
| 7 |
+
"""
|
| 8 |
+
import json
|
| 9 |
+
import os
|
| 10 |
+
import shutil
|
| 11 |
+
import subprocess
|
| 12 |
+
import sys
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
|
| 15 |
+
# ── Paths ─────────────────────────────────────────────────────────────────────
|
| 16 |
+
PROJECT_ROOT = Path(__file__).parent.parent
|
| 17 |
+
REPO_DIR = Path(os.environ.get("HF_REPO_DIR", r"C:\Users\naidu\AppData\Local\Temp\wdlm_model_push"))
|
| 18 |
+
HF_TOKEN = os.environ.get("HF_TOKEN", "")
|
| 19 |
+
HF_REPO = "drdeveloper88/WorldDisasterLM-8B"
|
| 20 |
+
|
| 21 |
+
# ── Correct language list from project README ─────────────────────────────────
|
| 22 |
+
LANGUAGES = ["en", "ne", "es", "fr", "ar", "hi", "te", "zh", "ja", "ko", "pt"]
|
| 23 |
+
LANGUAGE_NAMES = {
|
| 24 |
+
"en": "English", "ne": "Nepali (नेपाली)", "es": "Spanish",
|
| 25 |
+
"fr": "French", "ar": "Arabic", "hi": "Hindi",
|
| 26 |
+
"te": "Telugu", "zh": "Chinese", "ja": "Japanese",
|
| 27 |
+
"ko": "Korean", "pt": "Portuguese",
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
# ── 1. Build the HF model card README ────────────────────────────────────────
|
| 31 |
+
def build_readme():
|
| 32 |
+
# Read the actual project README content (strip the first H1 title line)
|
| 33 |
+
src_readme = (PROJECT_ROOT / "README.md").read_text(encoding="utf-8")
|
| 34 |
+
|
| 35 |
+
yaml_header = f"""---
|
| 36 |
+
language:
|
| 37 |
+
{chr(10).join(f" - {lang}" for lang in LANGUAGES)}
|
| 38 |
+
license: llama3
|
| 39 |
+
library_name: transformers
|
| 40 |
+
base_model: meta-llama/Llama-3.1-8B-Instruct
|
| 41 |
+
tags:
|
| 42 |
+
- disaster-management
|
| 43 |
+
- emergency-response
|
| 44 |
+
- humanitarian-ai
|
| 45 |
+
- multilingual
|
| 46 |
+
- fine-tuned
|
| 47 |
+
- qlora
|
| 48 |
+
- lora
|
| 49 |
+
- peft
|
| 50 |
+
- llama3
|
| 51 |
+
pipeline_tag: text-generation
|
| 52 |
+
model-index:
|
| 53 |
+
- name: WorldDisasterLM-8B
|
| 54 |
+
results: []
|
| 55 |
+
---
|
| 56 |
+
|
| 57 |
+
"""
|
| 58 |
+
return yaml_header + src_readme
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
# ── 2. Config files ───────────────────────────────────────────────────────────
|
| 62 |
+
def build_configs():
|
| 63 |
+
SYSTEM_PROMPT = (
|
| 64 |
+
"You are WorldDisasterLM-8B, an expert AI specialized in global disaster "
|
| 65 |
+
"management, emergency response, and humanitarian aid. You provide accurate, "
|
| 66 |
+
"actionable guidance in 11 languages: English, Nepali (नेपाली), Spanish, "
|
| 67 |
+
"French, Arabic, Hindi, Telugu, Chinese, Japanese, Korean, and Portuguese. "
|
| 68 |
+
"Always prioritize life safety. Cite authoritative sources (NDRRMA for Nepal, "
|
| 69 |
+
"WHO, FEMA, USGS, GDACS) when relevant. Never provide false hope or inaccurate "
|
| 70 |
+
"information in emergency situations."
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
CHAT_TEMPLATE = (
|
| 74 |
+
"{%- set default_system = \"" + SYSTEM_PROMPT.replace('"', "'") + "\" %}"
|
| 75 |
+
"{%- if messages[0]['role'] == 'system' %}"
|
| 76 |
+
"{%- set default_system = messages[0]['content'] %}"
|
| 77 |
+
"{%- set messages = messages[1:] %}"
|
| 78 |
+
"{%- endif %}"
|
| 79 |
+
"{{ bos_token }}"
|
| 80 |
+
"<|start_header_id|>system<|end_header_id|>\n\n{{ default_system }}<|eot_id|>"
|
| 81 |
+
"{%- for message in messages %}"
|
| 82 |
+
"{{ '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n' + message['content'] | trim + '<|eot_id|>' }}"
|
| 83 |
+
"{%- endfor %}"
|
| 84 |
+
"{%- if add_generation_prompt %}"
|
| 85 |
+
"{{ '<|start_header_id|>assistant<|end_header_id|>\n\n' }}"
|
| 86 |
+
"{%- endif %}"
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
configs = {
|
| 90 |
+
"config.json": {
|
| 91 |
+
"_name_or_path": "drdeveloper88/WorldDisasterLM-8B",
|
| 92 |
+
"architectures": ["LlamaForCausalLM"],
|
| 93 |
+
"attention_bias": False,
|
| 94 |
+
"attention_dropout": 0.0,
|
| 95 |
+
"bos_token_id": 128000,
|
| 96 |
+
"eos_token_id": [128001, 128008, 128009],
|
| 97 |
+
"head_dim": 128,
|
| 98 |
+
"hidden_act": "silu",
|
| 99 |
+
"hidden_size": 4096,
|
| 100 |
+
"initializer_range": 0.02,
|
| 101 |
+
"intermediate_size": 14336,
|
| 102 |
+
"max_position_embeddings": 131072,
|
| 103 |
+
"mlp_bias": False,
|
| 104 |
+
"model_type": "llama",
|
| 105 |
+
"num_attention_heads": 32,
|
| 106 |
+
"num_hidden_layers": 32,
|
| 107 |
+
"num_key_value_heads": 8,
|
| 108 |
+
"pretraining_tp": 1,
|
| 109 |
+
"rms_norm_eps": 1e-05,
|
| 110 |
+
"rope_interleaved": False,
|
| 111 |
+
"rope_scaling": {
|
| 112 |
+
"factor": 8.0,
|
| 113 |
+
"high_freq_factor": 4.0,
|
| 114 |
+
"low_freq_factor": 1.0,
|
| 115 |
+
"original_max_position_embeddings": 8192,
|
| 116 |
+
"rope_type": "llama3",
|
| 117 |
+
},
|
| 118 |
+
"rope_theta": 500000.0,
|
| 119 |
+
"tie_word_embeddings": False,
|
| 120 |
+
"torch_dtype": "bfloat16",
|
| 121 |
+
"transformers_version": "4.43.0",
|
| 122 |
+
"use_cache": True,
|
| 123 |
+
"vocab_size": 128256,
|
| 124 |
+
"quantization_config": {
|
| 125 |
+
"quant_method": "bitsandbytes",
|
| 126 |
+
"load_in_4bit": True,
|
| 127 |
+
"load_in_8bit": False,
|
| 128 |
+
"bnb_4bit_quant_type": "nf4",
|
| 129 |
+
"bnb_4bit_compute_dtype": "bfloat16",
|
| 130 |
+
"bnb_4bit_use_double_quant": True,
|
| 131 |
+
"bnb_4bit_quant_storage": "uint8",
|
| 132 |
+
"llm_int8_threshold": 6.0,
|
| 133 |
+
"llm_int8_skip_modules": None,
|
| 134 |
+
"llm_int8_enable_fp32_cpu_offload": False,
|
| 135 |
+
"llm_int8_has_fp16_weight": False,
|
| 136 |
+
},
|
| 137 |
+
},
|
| 138 |
+
"quantization_config.json": {
|
| 139 |
+
"quant_method": "bitsandbytes",
|
| 140 |
+
"load_in_4bit": True,
|
| 141 |
+
"load_in_8bit": False,
|
| 142 |
+
"bnb_4bit_quant_type": "nf4",
|
| 143 |
+
"bnb_4bit_compute_dtype": "bfloat16",
|
| 144 |
+
"bnb_4bit_use_double_quant": True,
|
| 145 |
+
"bnb_4bit_quant_storage": "uint8",
|
| 146 |
+
"llm_int8_threshold": 6.0,
|
| 147 |
+
"llm_int8_skip_modules": None,
|
| 148 |
+
"llm_int8_enable_fp32_cpu_offload": False,
|
| 149 |
+
"llm_int8_has_fp16_weight": False,
|
| 150 |
+
},
|
| 151 |
+
"adapter_config.json": {
|
| 152 |
+
"_version": "0.7.1",
|
| 153 |
+
"alpha_pattern": {},
|
| 154 |
+
"auto_mapping": None,
|
| 155 |
+
"base_model_name_or_path": "meta-llama/Llama-3.1-8B-Instruct",
|
| 156 |
+
"bias": "none",
|
| 157 |
+
"fan_in_fan_out": False,
|
| 158 |
+
"inference_mode": True,
|
| 159 |
+
"init_lora_weights": True,
|
| 160 |
+
"layer_replication": None,
|
| 161 |
+
"loftq_config": {},
|
| 162 |
+
"lora_alpha": 32,
|
| 163 |
+
"lora_dropout": 0.05,
|
| 164 |
+
"modules_to_save": None,
|
| 165 |
+
"peft_type": "LORA",
|
| 166 |
+
"r": 16,
|
| 167 |
+
"rank_pattern": {},
|
| 168 |
+
"revision": None,
|
| 169 |
+
"target_modules": [
|
| 170 |
+
"q_proj", "k_proj", "v_proj", "o_proj",
|
| 171 |
+
"gate_proj", "up_proj", "down_proj",
|
| 172 |
+
],
|
| 173 |
+
"task_type": "CAUSAL_LM",
|
| 174 |
+
"use_dora": False,
|
| 175 |
+
"use_rslora": False,
|
| 176 |
+
"trainable_parameters": "41,943,040",
|
| 177 |
+
"total_parameters": "8,030,261,248",
|
| 178 |
+
"trainable_pct": "0.52%",
|
| 179 |
+
},
|
| 180 |
+
"tokenizer_config.json": {
|
| 181 |
+
"add_bos_token": True,
|
| 182 |
+
"add_eos_token": False,
|
| 183 |
+
"add_prefix_space": None,
|
| 184 |
+
"bos_token": "<|begin_of_text|>",
|
| 185 |
+
"chat_template": CHAT_TEMPLATE,
|
| 186 |
+
"clean_up_tokenization_spaces": True,
|
| 187 |
+
"eos_token": "<|eot_id|>",
|
| 188 |
+
"model_max_length": 131072,
|
| 189 |
+
"pad_token": "<|end_of_text|>",
|
| 190 |
+
"padding_side": "right",
|
| 191 |
+
"tokenizer_class": "PreTrainedTokenizerFast",
|
| 192 |
+
"unk_token": None,
|
| 193 |
+
},
|
| 194 |
+
"generation_config.json": {
|
| 195 |
+
"_from_model_config": False,
|
| 196 |
+
"bos_token_id": 128000,
|
| 197 |
+
"do_sample": True,
|
| 198 |
+
"eos_token_id": [128001, 128008, 128009],
|
| 199 |
+
"max_new_tokens": 512,
|
| 200 |
+
"min_new_tokens": 10,
|
| 201 |
+
"temperature": 0.7,
|
| 202 |
+
"top_p": 0.9,
|
| 203 |
+
"top_k": 50,
|
| 204 |
+
"repetition_penalty": 1.1,
|
| 205 |
+
"no_repeat_ngram_size": 3,
|
| 206 |
+
"transformers_version": "4.43.0",
|
| 207 |
+
},
|
| 208 |
+
"special_tokens_map.json": {
|
| 209 |
+
"bos_token": {
|
| 210 |
+
"content": "<|begin_of_text|>",
|
| 211 |
+
"lstrip": False, "normalized": False, "rstrip": False, "single_word": False,
|
| 212 |
+
},
|
| 213 |
+
"eos_token": {
|
| 214 |
+
"content": "<|eot_id|>",
|
| 215 |
+
"lstrip": False, "normalized": False, "rstrip": False, "single_word": False,
|
| 216 |
+
},
|
| 217 |
+
"pad_token": {
|
| 218 |
+
"content": "<|end_of_text|>",
|
| 219 |
+
"lstrip": False, "normalized": False, "rstrip": False, "single_word": False,
|
| 220 |
+
},
|
| 221 |
+
"additional_special_tokens": [
|
| 222 |
+
"<|start_header_id|>", "<|end_header_id|>", "<|eot_id|>",
|
| 223 |
+
"<|begin_of_text|>", "<|end_of_text|>",
|
| 224 |
+
],
|
| 225 |
+
},
|
| 226 |
+
"training_args.json": {
|
| 227 |
+
"model_name_or_path": "meta-llama/Llama-3.1-8B-Instruct",
|
| 228 |
+
"output_dir": "./outputs/WorldDisasterLM-8B",
|
| 229 |
+
"num_train_epochs": 3,
|
| 230 |
+
"per_device_train_batch_size": 4,
|
| 231 |
+
"per_device_eval_batch_size": 4,
|
| 232 |
+
"gradient_accumulation_steps": 4,
|
| 233 |
+
"gradient_checkpointing": True,
|
| 234 |
+
"learning_rate": 2e-4,
|
| 235 |
+
"lr_scheduler_type": "cosine",
|
| 236 |
+
"warmup_ratio": 0.03,
|
| 237 |
+
"weight_decay": 0.001,
|
| 238 |
+
"max_grad_norm": 0.3,
|
| 239 |
+
"optim": "paged_adamw_32bit",
|
| 240 |
+
"fp16": False,
|
| 241 |
+
"bf16": True,
|
| 242 |
+
"max_seq_length": 4096,
|
| 243 |
+
"packing": True,
|
| 244 |
+
"lora_r": 16,
|
| 245 |
+
"lora_alpha": 32,
|
| 246 |
+
"lora_dropout": 0.05,
|
| 247 |
+
"lora_target_modules": [
|
| 248 |
+
"q_proj", "k_proj", "v_proj", "o_proj",
|
| 249 |
+
"gate_proj", "up_proj", "down_proj",
|
| 250 |
+
],
|
| 251 |
+
"use_4bit": True,
|
| 252 |
+
"bnb_4bit_quant_type": "nf4",
|
| 253 |
+
"bnb_4bit_compute_dtype": "bfloat16",
|
| 254 |
+
"use_nested_quant": True,
|
| 255 |
+
"save_steps": 100,
|
| 256 |
+
"logging_steps": 25,
|
| 257 |
+
"evaluation_strategy": "steps",
|
| 258 |
+
"eval_steps": 100,
|
| 259 |
+
"save_total_limit": 3,
|
| 260 |
+
"load_best_model_at_end": True,
|
| 261 |
+
"metric_for_best_model": "eval_loss",
|
| 262 |
+
"dataloader_num_workers": 4,
|
| 263 |
+
"seed": 42,
|
| 264 |
+
"report_to": ["tensorboard"],
|
| 265 |
+
"dataset_sources": ["ReliefWeb", "USGS", "GDACS", "NOAA", "OpenFEMA", "WHO"],
|
| 266 |
+
"dataset_size": "88+ live records → 711+ instruction samples per run",
|
| 267 |
+
"languages": LANGUAGES,
|
| 268 |
+
"language_names": list(LANGUAGE_NAMES.values()),
|
| 269 |
+
"training_status": "PENDING — weights not yet generated. Run: python train.py",
|
| 270 |
+
},
|
| 271 |
+
}
|
| 272 |
+
return configs
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
# ── 3. Files to copy from project root ───────────────────────────────────────
|
| 276 |
+
ROOT_FILES = [
|
| 277 |
+
"train.py", "evaluate.py", "inference.py", "dataset_builder.py",
|
| 278 |
+
"app.py", "conftest.py", "requirements.txt", "pyproject.toml",
|
| 279 |
+
"Dockerfile", "docker-compose.yml", "Makefile", ".env.example",
|
| 280 |
+
"LICENSE", "MODEL_CARD.md", ".gitignore",
|
| 281 |
+
]
|
| 282 |
+
|
| 283 |
+
ROOT_DIRS = [
|
| 284 |
+
"backend", "worlddisasterlm", "scripts", "tests", "hf_space", "docs", ".github",
|
| 285 |
+
]
|
| 286 |
+
|
| 287 |
+
EXCLUDE_DIRS = {".venv", "__pycache__", ".pytest_cache", "node_modules",
|
| 288 |
+
".git", "data", "outputs", "checkpoints", "artifacts"}
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
def copy_tree(src: Path, dst: Path):
|
| 292 |
+
dst.mkdir(parents=True, exist_ok=True)
|
| 293 |
+
for item in src.iterdir():
|
| 294 |
+
if item.name in EXCLUDE_DIRS:
|
| 295 |
+
continue
|
| 296 |
+
if item.is_dir():
|
| 297 |
+
copy_tree(item, dst / item.name)
|
| 298 |
+
else:
|
| 299 |
+
shutil.copy2(item, dst / item.name)
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
def run(cmd: list[str], cwd: Path = None):
|
| 303 |
+
result = subprocess.run(cmd, cwd=cwd or REPO_DIR, capture_output=True, text=True)
|
| 304 |
+
if result.returncode != 0:
|
| 305 |
+
print(f"STDERR: {result.stderr[-500:]}")
|
| 306 |
+
return result.returncode == 0
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
# ── 4. Main ───────────────────────────────────────────────────────────────────
|
| 310 |
+
def main():
|
| 311 |
+
print(f"Syncing to: {REPO_DIR}")
|
| 312 |
+
print(f"HF repo: {HF_REPO}\n")
|
| 313 |
+
|
| 314 |
+
# Git config
|
| 315 |
+
run(["git", "config", "http.sslBackend", "schannel"])
|
| 316 |
+
run(["git", "config", "user.email", "drdeveloper88@users.noreply.huggingface.co"])
|
| 317 |
+
run(["git", "config", "user.name", "drdeveloper88"])
|
| 318 |
+
|
| 319 |
+
# Write README
|
| 320 |
+
print("Writing README.md (model card)...")
|
| 321 |
+
readme = build_readme()
|
| 322 |
+
(REPO_DIR / "README.md").write_text(readme, encoding="utf-8")
|
| 323 |
+
|
| 324 |
+
# Write config files
|
| 325 |
+
print("Writing config files...")
|
| 326 |
+
configs = build_configs()
|
| 327 |
+
for fname, data in configs.items():
|
| 328 |
+
path = REPO_DIR / fname
|
| 329 |
+
with open(path, "w", encoding="utf-8") as f:
|
| 330 |
+
json.dump(data, f, indent=2, ensure_ascii=False)
|
| 331 |
+
print(f" {fname} ({path.stat().st_size} bytes)")
|
| 332 |
+
|
| 333 |
+
# Copy root files
|
| 334 |
+
print("\nCopying project root files...")
|
| 335 |
+
for fname in ROOT_FILES:
|
| 336 |
+
src = PROJECT_ROOT / fname
|
| 337 |
+
if src.exists():
|
| 338 |
+
shutil.copy2(src, REPO_DIR / fname)
|
| 339 |
+
print(f" {fname}")
|
| 340 |
+
|
| 341 |
+
# Copy directories
|
| 342 |
+
print("\nCopying project directories...")
|
| 343 |
+
for dname in ROOT_DIRS:
|
| 344 |
+
src = PROJECT_ROOT / dname
|
| 345 |
+
if src.exists():
|
| 346 |
+
dst = REPO_DIR / dname
|
| 347 |
+
if dst.exists():
|
| 348 |
+
shutil.rmtree(dst)
|
| 349 |
+
copy_tree(src, dst)
|
| 350 |
+
print(f" {dname}/")
|
| 351 |
+
|
| 352 |
+
# Git add + commit + push
|
| 353 |
+
print("\nStaging changes...")
|
| 354 |
+
run(["git", "add", "-A"])
|
| 355 |
+
|
| 356 |
+
result = subprocess.run(
|
| 357 |
+
["git", "status", "--short"], cwd=REPO_DIR, capture_output=True, text=True
|
| 358 |
+
)
|
| 359 |
+
changed = result.stdout.strip()
|
| 360 |
+
if not changed:
|
| 361 |
+
print("Nothing new to commit — repo is up to date.")
|
| 362 |
+
return
|
| 363 |
+
|
| 364 |
+
print(f"Changed files:\n{changed}\n")
|
| 365 |
+
commit_msg = (
|
| 366 |
+
"Sync: correct language list (en/ne/es/fr/ar/hi/te/zh/ja/ko/pt), "
|
| 367 |
+
"updated README from project, full source code sync"
|
| 368 |
+
)
|
| 369 |
+
run(["git", "commit", "-m", commit_msg])
|
| 370 |
+
|
| 371 |
+
print("Pushing to HuggingFace...")
|
| 372 |
+
ok = run(["git", "push", "origin", "main"])
|
| 373 |
+
if ok:
|
| 374 |
+
print(f"\nDone! Live at: https://huggingface.co/{HF_REPO}")
|
| 375 |
+
else:
|
| 376 |
+
print("Push failed — check git output above.")
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
if __name__ == "__main__":
|
| 380 |
+
main()
|
scripts/write_hf_configs.py
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Write best-practice HuggingFace model config files to the given output directory."""
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
|
| 6 |
+
out_dir = sys.argv[1] if len(sys.argv) > 1 else "."
|
| 7 |
+
|
| 8 |
+
# ── 1. config.json ──────────────────────────────────────────────────────────
|
| 9 |
+
config = {
|
| 10 |
+
"_name_or_path": "drdeveloper88/WorldDisasterLM-8B",
|
| 11 |
+
"architectures": ["LlamaForCausalLM"],
|
| 12 |
+
"attention_bias": False,
|
| 13 |
+
"attention_dropout": 0.0,
|
| 14 |
+
"bos_token_id": 128000,
|
| 15 |
+
"eos_token_id": [128001, 128008, 128009],
|
| 16 |
+
"head_dim": 128,
|
| 17 |
+
"hidden_act": "silu",
|
| 18 |
+
"hidden_size": 4096,
|
| 19 |
+
"initializer_range": 0.02,
|
| 20 |
+
"intermediate_size": 14336,
|
| 21 |
+
"max_position_embeddings": 131072,
|
| 22 |
+
"mlp_bias": False,
|
| 23 |
+
"model_type": "llama",
|
| 24 |
+
"num_attention_heads": 32,
|
| 25 |
+
"num_hidden_layers": 32,
|
| 26 |
+
"num_key_value_heads": 8,
|
| 27 |
+
"pretraining_tp": 1,
|
| 28 |
+
"rms_norm_eps": 1e-05,
|
| 29 |
+
"rope_interleaved": False,
|
| 30 |
+
"rope_scaling": {
|
| 31 |
+
"factor": 8.0,
|
| 32 |
+
"high_freq_factor": 4.0,
|
| 33 |
+
"low_freq_factor": 1.0,
|
| 34 |
+
"original_max_position_embeddings": 8192,
|
| 35 |
+
"rope_type": "llama3",
|
| 36 |
+
},
|
| 37 |
+
"rope_theta": 500000.0,
|
| 38 |
+
"tie_word_embeddings": False,
|
| 39 |
+
"torch_dtype": "bfloat16",
|
| 40 |
+
"transformers_version": "4.43.0",
|
| 41 |
+
"use_cache": True,
|
| 42 |
+
"vocab_size": 128256,
|
| 43 |
+
"quantization_config": {
|
| 44 |
+
"quant_method": "bitsandbytes",
|
| 45 |
+
"load_in_4bit": True,
|
| 46 |
+
"load_in_8bit": False,
|
| 47 |
+
"bnb_4bit_quant_type": "nf4",
|
| 48 |
+
"bnb_4bit_compute_dtype": "bfloat16",
|
| 49 |
+
"bnb_4bit_use_double_quant": True,
|
| 50 |
+
"bnb_4bit_quant_storage": "uint8",
|
| 51 |
+
"llm_int8_threshold": 6.0,
|
| 52 |
+
"llm_int8_skip_modules": None,
|
| 53 |
+
"llm_int8_enable_fp32_cpu_offload": False,
|
| 54 |
+
"llm_int8_has_fp16_weight": False,
|
| 55 |
+
},
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
# ── 2. quantization_config.json (standalone BitsAndBytes NF4) ───────────────
|
| 59 |
+
quantization_config = {
|
| 60 |
+
"quant_method": "bitsandbytes",
|
| 61 |
+
"load_in_4bit": True,
|
| 62 |
+
"load_in_8bit": False,
|
| 63 |
+
"bnb_4bit_quant_type": "nf4",
|
| 64 |
+
"bnb_4bit_compute_dtype": "bfloat16",
|
| 65 |
+
"bnb_4bit_use_double_quant": True,
|
| 66 |
+
"bnb_4bit_quant_storage": "uint8",
|
| 67 |
+
"llm_int8_threshold": 6.0,
|
| 68 |
+
"llm_int8_skip_modules": None,
|
| 69 |
+
"llm_int8_enable_fp32_cpu_offload": False,
|
| 70 |
+
"llm_int8_has_fp16_weight": False,
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
# ── 3. adapter_config.json (full PEFT LoRA) ──────────────────────────────────
|
| 74 |
+
adapter_config = {
|
| 75 |
+
"_version": "0.7.1",
|
| 76 |
+
"alpha_pattern": {},
|
| 77 |
+
"auto_mapping": None,
|
| 78 |
+
"base_model_name_or_path": "meta-llama/Llama-3.1-8B-Instruct",
|
| 79 |
+
"bias": "none",
|
| 80 |
+
"fan_in_fan_out": False,
|
| 81 |
+
"inference_mode": True,
|
| 82 |
+
"init_lora_weights": True,
|
| 83 |
+
"layer_replication": None,
|
| 84 |
+
"loftq_config": {},
|
| 85 |
+
"lora_alpha": 32,
|
| 86 |
+
"lora_dropout": 0.05,
|
| 87 |
+
"modules_to_save": None,
|
| 88 |
+
"peft_type": "LORA",
|
| 89 |
+
"r": 16,
|
| 90 |
+
"rank_pattern": {},
|
| 91 |
+
"revision": None,
|
| 92 |
+
"target_modules": [
|
| 93 |
+
"q_proj", "k_proj", "v_proj", "o_proj",
|
| 94 |
+
"gate_proj", "up_proj", "down_proj",
|
| 95 |
+
],
|
| 96 |
+
"task_type": "CAUSAL_LM",
|
| 97 |
+
"use_dora": False,
|
| 98 |
+
"use_rslora": False,
|
| 99 |
+
"trainable_parameters": "41,943,040",
|
| 100 |
+
"total_parameters": "8,030,261,248",
|
| 101 |
+
"trainable_pct": "0.52%",
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
# ── 4. tokenizer_config.json with disaster-domain system prompt ──────────────
|
| 105 |
+
SYSTEM_PROMPT = (
|
| 106 |
+
"You are WorldDisasterLM-8B, an expert AI specialized in global disaster "
|
| 107 |
+
"management, emergency response, and humanitarian aid. You provide accurate, "
|
| 108 |
+
"actionable guidance in 11 languages including Nepali, Hindi, Arabic, French, "
|
| 109 |
+
"Spanish, Swahili, Indonesian, Portuguese, Chinese, and Bengali. "
|
| 110 |
+
"Always prioritize life safety. Cite authoritative sources (NDRRMA for Nepal, "
|
| 111 |
+
"WHO, FEMA, GDACS, USGS) when relevant. Never provide false hope or inaccurate "
|
| 112 |
+
"information in emergency situations."
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
# Jinja2 chat template with hardcoded disaster system prompt as default
|
| 116 |
+
CHAT_TEMPLATE = (
|
| 117 |
+
"{%- set default_system = \"" + SYSTEM_PROMPT.replace('"', "'") + "\" %}"
|
| 118 |
+
"{%- if messages[0]['role'] == 'system' %}"
|
| 119 |
+
"{%- set default_system = messages[0]['content'] %}"
|
| 120 |
+
"{%- set messages = messages[1:] %}"
|
| 121 |
+
"{%- endif %}"
|
| 122 |
+
"{{ bos_token }}"
|
| 123 |
+
"<|start_header_id|>system<|end_header_id|>\n\n{{ default_system }}<|eot_id|>"
|
| 124 |
+
"{%- for message in messages %}"
|
| 125 |
+
"{{ '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n' + message['content'] | trim + '<|eot_id|>' }}"
|
| 126 |
+
"{%- endfor %}"
|
| 127 |
+
"{%- if add_generation_prompt %}"
|
| 128 |
+
"{{ '<|start_header_id|>assistant<|end_header_id|>\n\n' }}"
|
| 129 |
+
"{%- endif %}"
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
tokenizer_config = {
|
| 133 |
+
"add_bos_token": True,
|
| 134 |
+
"add_eos_token": False,
|
| 135 |
+
"add_prefix_space": None,
|
| 136 |
+
"bos_token": "<|begin_of_text|>",
|
| 137 |
+
"chat_template": CHAT_TEMPLATE,
|
| 138 |
+
"clean_up_tokenization_spaces": True,
|
| 139 |
+
"eos_token": "<|eot_id|>",
|
| 140 |
+
"model_max_length": 131072,
|
| 141 |
+
"pad_token": "<|end_of_text|>",
|
| 142 |
+
"padding_side": "right",
|
| 143 |
+
"tokenizer_class": "PreTrainedTokenizerFast",
|
| 144 |
+
"unk_token": None,
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
# ── 5. generation_config.json ────────────────────────────────────────────────
|
| 148 |
+
generation_config = {
|
| 149 |
+
"_from_model_config": False,
|
| 150 |
+
"bos_token_id": 128000,
|
| 151 |
+
"do_sample": True,
|
| 152 |
+
"eos_token_id": [128001, 128008, 128009],
|
| 153 |
+
"max_new_tokens": 512,
|
| 154 |
+
"min_new_tokens": 10,
|
| 155 |
+
"temperature": 0.7,
|
| 156 |
+
"top_p": 0.9,
|
| 157 |
+
"top_k": 50,
|
| 158 |
+
"repetition_penalty": 1.1,
|
| 159 |
+
"no_repeat_ngram_size": 3,
|
| 160 |
+
"transformers_version": "4.43.0",
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
# ── 6. special_tokens_map.json ───────────────────────────────────────────────
|
| 164 |
+
special_tokens_map = {
|
| 165 |
+
"bos_token": {
|
| 166 |
+
"content": "<|begin_of_text|>",
|
| 167 |
+
"lstrip": False, "normalized": False, "rstrip": False, "single_word": False,
|
| 168 |
+
},
|
| 169 |
+
"eos_token": {
|
| 170 |
+
"content": "<|eot_id|>",
|
| 171 |
+
"lstrip": False, "normalized": False, "rstrip": False, "single_word": False,
|
| 172 |
+
},
|
| 173 |
+
"pad_token": {
|
| 174 |
+
"content": "<|end_of_text|>",
|
| 175 |
+
"lstrip": False, "normalized": False, "rstrip": False, "single_word": False,
|
| 176 |
+
},
|
| 177 |
+
"additional_special_tokens": [
|
| 178 |
+
"<|start_header_id|>", "<|end_header_id|>", "<|eot_id|>",
|
| 179 |
+
"<|begin_of_text|>", "<|end_of_text|>",
|
| 180 |
+
],
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
# ── 7. training_args.json — QLoRA hyperparameters ────────────────────────────
|
| 184 |
+
training_args = {
|
| 185 |
+
"model_name_or_path": "meta-llama/Llama-3.1-8B-Instruct",
|
| 186 |
+
"output_dir": "./outputs/WorldDisasterLM-8B",
|
| 187 |
+
"num_train_epochs": 3,
|
| 188 |
+
"per_device_train_batch_size": 4,
|
| 189 |
+
"per_device_eval_batch_size": 4,
|
| 190 |
+
"gradient_accumulation_steps": 4,
|
| 191 |
+
"gradient_checkpointing": True,
|
| 192 |
+
"learning_rate": 2e-4,
|
| 193 |
+
"lr_scheduler_type": "cosine",
|
| 194 |
+
"warmup_ratio": 0.03,
|
| 195 |
+
"weight_decay": 0.001,
|
| 196 |
+
"max_grad_norm": 0.3,
|
| 197 |
+
"optim": "paged_adamw_32bit",
|
| 198 |
+
"fp16": False,
|
| 199 |
+
"bf16": True,
|
| 200 |
+
"max_seq_length": 4096,
|
| 201 |
+
"packing": True,
|
| 202 |
+
"lora_r": 16,
|
| 203 |
+
"lora_alpha": 32,
|
| 204 |
+
"lora_dropout": 0.05,
|
| 205 |
+
"lora_target_modules": [
|
| 206 |
+
"q_proj", "k_proj", "v_proj", "o_proj",
|
| 207 |
+
"gate_proj", "up_proj", "down_proj",
|
| 208 |
+
],
|
| 209 |
+
"use_4bit": True,
|
| 210 |
+
"bnb_4bit_quant_type": "nf4",
|
| 211 |
+
"bnb_4bit_compute_dtype": "bfloat16",
|
| 212 |
+
"use_nested_quant": True,
|
| 213 |
+
"save_steps": 100,
|
| 214 |
+
"logging_steps": 25,
|
| 215 |
+
"evaluation_strategy": "steps",
|
| 216 |
+
"eval_steps": 100,
|
| 217 |
+
"save_total_limit": 3,
|
| 218 |
+
"load_best_model_at_end": True,
|
| 219 |
+
"metric_for_best_model": "eval_loss",
|
| 220 |
+
"dataloader_num_workers": 4,
|
| 221 |
+
"seed": 42,
|
| 222 |
+
"report_to": ["tensorboard"],
|
| 223 |
+
"dataset_sources": ["ReliefWeb", "USGS", "GDACS", "NOAA", "OpenFEMA", "WHO"],
|
| 224 |
+
"languages": ["en", "ne", "hi", "ar", "fr", "es", "sw", "id", "pt", "zh", "bn"],
|
| 225 |
+
"training_status": "PENDING — weights not yet generated. Run train.py to produce weights.",
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
# ── Write all files ───────────────────────────────────────────────────────────
|
| 229 |
+
files = {
|
| 230 |
+
"config.json": config,
|
| 231 |
+
"quantization_config.json": quantization_config,
|
| 232 |
+
"adapter_config.json": adapter_config,
|
| 233 |
+
"tokenizer_config.json": tokenizer_config,
|
| 234 |
+
"generation_config.json": generation_config,
|
| 235 |
+
"special_tokens_map.json": special_tokens_map,
|
| 236 |
+
"training_args.json": training_args,
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
for fname, data in files.items():
|
| 240 |
+
path = os.path.join(out_dir, fname)
|
| 241 |
+
with open(path, "w", encoding="utf-8") as f:
|
| 242 |
+
json.dump(data, f, indent=2, ensure_ascii=False)
|
| 243 |
+
size = os.path.getsize(path)
|
| 244 |
+
print(f" {fname:35s} {size:>6} bytes")
|
| 245 |
+
|
| 246 |
+
print(f"\nAll {len(files)} config files written to: {os.path.abspath(out_dir)}")
|
tokenizer_config.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
"add_eos_token": false,
|
| 4 |
"add_prefix_space": null,
|
| 5 |
"bos_token": "<|begin_of_text|>",
|
| 6 |
-
"chat_template": "{%- set default_system = \"You are WorldDisasterLM-8B, an expert AI specialized in global disaster management, emergency response, and humanitarian aid. You provide accurate, actionable guidance in 11 languages
|
| 7 |
"clean_up_tokenization_spaces": true,
|
| 8 |
"eos_token": "<|eot_id|>",
|
| 9 |
"model_max_length": 131072,
|
|
|
|
| 3 |
"add_eos_token": false,
|
| 4 |
"add_prefix_space": null,
|
| 5 |
"bos_token": "<|begin_of_text|>",
|
| 6 |
+
"chat_template": "{%- set default_system = \"You are WorldDisasterLM-8B, an expert AI specialized in global disaster management, emergency response, and humanitarian aid. You provide accurate, actionable guidance in 11 languages: English, Nepali (नेपाली), Spanish, French, Arabic, Hindi, Telugu, Chinese, Japanese, Korean, and Portuguese. Always prioritize life safety. Cite authoritative sources (NDRRMA for Nepal, WHO, FEMA, USGS, GDACS) when relevant. Never provide false hope or inaccurate information in emergency situations.\" %}{%- if messages[0]['role'] == 'system' %}{%- set default_system = messages[0]['content'] %}{%- set messages = messages[1:] %}{%- endif %}{{ bos_token }}<|start_header_id|>system<|end_header_id|>\n\n{{ default_system }}<|eot_id|>{%- for message in messages %}{{ '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n' + message['content'] | trim + '<|eot_id|>' }}{%- endfor %}{%- if add_generation_prompt %}{{ '<|start_header_id|>assistant<|end_header_id|>\n\n' }}{%- endif %}",
|
| 7 |
"clean_up_tokenization_spaces": true,
|
| 8 |
"eos_token": "<|eot_id|>",
|
| 9 |
"model_max_length": 131072,
|
training_args.json
CHANGED
|
@@ -52,18 +52,32 @@
|
|
| 52 |
"OpenFEMA",
|
| 53 |
"WHO"
|
| 54 |
],
|
|
|
|
| 55 |
"languages": [
|
| 56 |
"en",
|
| 57 |
"ne",
|
| 58 |
-
"hi",
|
| 59 |
-
"ar",
|
| 60 |
-
"fr",
|
| 61 |
"es",
|
| 62 |
-
"
|
| 63 |
-
"
|
| 64 |
-
"
|
|
|
|
| 65 |
"zh",
|
| 66 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
],
|
| 68 |
-
"training_status": "PENDING — weights not yet generated. Run train.py
|
| 69 |
}
|
|
|
|
| 52 |
"OpenFEMA",
|
| 53 |
"WHO"
|
| 54 |
],
|
| 55 |
+
"dataset_size": "88+ live records → 711+ instruction samples per run",
|
| 56 |
"languages": [
|
| 57 |
"en",
|
| 58 |
"ne",
|
|
|
|
|
|
|
|
|
|
| 59 |
"es",
|
| 60 |
+
"fr",
|
| 61 |
+
"ar",
|
| 62 |
+
"hi",
|
| 63 |
+
"te",
|
| 64 |
"zh",
|
| 65 |
+
"ja",
|
| 66 |
+
"ko",
|
| 67 |
+
"pt"
|
| 68 |
+
],
|
| 69 |
+
"language_names": [
|
| 70 |
+
"English",
|
| 71 |
+
"Nepali (नेपाली)",
|
| 72 |
+
"Spanish",
|
| 73 |
+
"French",
|
| 74 |
+
"Arabic",
|
| 75 |
+
"Hindi",
|
| 76 |
+
"Telugu",
|
| 77 |
+
"Chinese",
|
| 78 |
+
"Japanese",
|
| 79 |
+
"Korean",
|
| 80 |
+
"Portuguese"
|
| 81 |
],
|
| 82 |
+
"training_status": "PENDING — weights not yet generated. Run: python train.py"
|
| 83 |
}
|