Spaces:
Running
Running
finetune: update the params to run experiment on H200
Browse files- finetune/README.md +9 -4
- finetune/train_modal_qwen35.py +9 -9
- src/gazet/search.py +5 -3
finetune/README.md
CHANGED
|
@@ -117,8 +117,13 @@ uv run \
|
|
| 117 |
--with torch \
|
| 118 |
python convert_hf_to_gguf.py \
|
| 119 |
./finetune/models/qwen35-v1-merged \
|
| 120 |
-
--outtype
|
| 121 |
-
--outfile ./finetune/models/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
```
|
| 123 |
|
| 124 |
---
|
|
@@ -129,7 +134,7 @@ uv run \
|
|
| 129 |
|
| 130 |
```bash
|
| 131 |
llama-server \
|
| 132 |
-
-m finetune/models/
|
| 133 |
-ngl 99 \
|
| 134 |
--port 9000 \
|
| 135 |
--ctx-size 2048
|
|
@@ -151,7 +156,7 @@ docker run \
|
|
| 151 |
-v $(pwd)/finetune/models:/models \
|
| 152 |
-p 9000:9000 \
|
| 153 |
ghcr.io/ggml-org/llama.cpp:server \
|
| 154 |
-
-m /models/
|
| 155 |
--port 9000 --host 0.0.0.0 \
|
| 156 |
--ctx-size 2048 -t 2 -v
|
| 157 |
```
|
|
|
|
| 117 |
--with torch \
|
| 118 |
python convert_hf_to_gguf.py \
|
| 119 |
./finetune/models/qwen35-v1-merged \
|
| 120 |
+
--outtype bf16 \
|
| 121 |
+
--outfile ./finetune/models/ckpt-bf16.gguf
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
# Quantize to 8-bits
|
| 125 |
+
```
|
| 126 |
+
llama-quantize ckpt-bf16.gguf ckpt-q8_0.gguf Q8_0
|
| 127 |
```
|
| 128 |
|
| 129 |
---
|
|
|
|
| 134 |
|
| 135 |
```bash
|
| 136 |
llama-server \
|
| 137 |
+
-m finetune/models/ckpt-q8_0.gguf \
|
| 138 |
-ngl 99 \
|
| 139 |
--port 9000 \
|
| 140 |
--ctx-size 2048
|
|
|
|
| 156 |
-v $(pwd)/finetune/models:/models \
|
| 157 |
-p 9000:9000 \
|
| 158 |
ghcr.io/ggml-org/llama.cpp:server \
|
| 159 |
+
-m /models/ckpt-q8_0.gguf \
|
| 160 |
--port 9000 --host 0.0.0.0 \
|
| 161 |
--ctx-size 2048 -t 2 -v
|
| 162 |
```
|
finetune/train_modal_qwen35.py
CHANGED
|
@@ -25,7 +25,7 @@ import modal
|
|
| 25 |
|
| 26 |
app = modal.App("gazet-nlg-qwen35-finetune-v2")
|
| 27 |
|
| 28 |
-
GPU_TYPE = "
|
| 29 |
TIMEOUT_HOURS = 24
|
| 30 |
MAX_RETRIES = 1
|
| 31 |
|
|
@@ -88,9 +88,9 @@ class Qwen35Config:
|
|
| 88 |
|
| 89 |
# Training
|
| 90 |
num_train_epochs: int = 1
|
| 91 |
-
per_device_train_batch_size: int =
|
| 92 |
-
per_device_eval_batch_size: int =
|
| 93 |
-
gradient_accumulation_steps: int = 1 # effective batch =
|
| 94 |
learning_rate: float = 1e-4
|
| 95 |
max_grad_norm: float = 1.0
|
| 96 |
warmup_steps: int = 50
|
|
@@ -99,17 +99,17 @@ class Qwen35Config:
|
|
| 99 |
optim: str = "adamw_8bit"
|
| 100 |
|
| 101 |
# Logging / saving
|
| 102 |
-
logging_steps: int =
|
| 103 |
save_strategy: str = "steps"
|
| 104 |
-
save_steps: int =
|
| 105 |
eval_strategy: str = "steps"
|
| 106 |
-
eval_steps: int =
|
| 107 |
report_to: str = "trackio"
|
| 108 |
trackio_space_id: Optional[str] = "srmsoumya/gazet-trackio"
|
| 109 |
project: str = "gazet-nlg-qwen35"
|
| 110 |
|
| 111 |
# Experiment
|
| 112 |
-
seed: int =
|
| 113 |
experiment_name: Optional[str] = None
|
| 114 |
|
| 115 |
def __post_init__(self):
|
|
@@ -169,7 +169,7 @@ def _load_data(run_dir: str, tokenizer, max_train_samples=None, max_eval_samples
|
|
| 169 |
ds_dict[split] = Dataset.from_list(combined)
|
| 170 |
print(f"{split} split: {len(combined):,} total rows")
|
| 171 |
|
| 172 |
-
ds = DatasetDict(ds_dict).shuffle(seed=
|
| 173 |
|
| 174 |
if max_train_samples is not None and "train" in ds:
|
| 175 |
ds["train"] = ds["train"].select(range(min(max_train_samples, len(ds["train"]))))
|
|
|
|
| 25 |
|
| 26 |
app = modal.App("gazet-nlg-qwen35-finetune-v2")
|
| 27 |
|
| 28 |
+
GPU_TYPE = "H200"
|
| 29 |
TIMEOUT_HOURS = 24
|
| 30 |
MAX_RETRIES = 1
|
| 31 |
|
|
|
|
| 88 |
|
| 89 |
# Training
|
| 90 |
num_train_epochs: int = 1
|
| 91 |
+
per_device_train_batch_size: int = 96
|
| 92 |
+
per_device_eval_batch_size: int = 48
|
| 93 |
+
gradient_accumulation_steps: int = 1 # effective batch = 96
|
| 94 |
learning_rate: float = 1e-4
|
| 95 |
max_grad_norm: float = 1.0
|
| 96 |
warmup_steps: int = 50
|
|
|
|
| 99 |
optim: str = "adamw_8bit"
|
| 100 |
|
| 101 |
# Logging / saving
|
| 102 |
+
logging_steps: int = 5
|
| 103 |
save_strategy: str = "steps"
|
| 104 |
+
save_steps: int = 700
|
| 105 |
eval_strategy: str = "steps"
|
| 106 |
+
eval_steps: int = 170
|
| 107 |
report_to: str = "trackio"
|
| 108 |
trackio_space_id: Optional[str] = "srmsoumya/gazet-trackio"
|
| 109 |
project: str = "gazet-nlg-qwen35"
|
| 110 |
|
| 111 |
# Experiment
|
| 112 |
+
seed: int = 108
|
| 113 |
experiment_name: Optional[str] = None
|
| 114 |
|
| 115 |
def __post_init__(self):
|
|
|
|
| 169 |
ds_dict[split] = Dataset.from_list(combined)
|
| 170 |
print(f"{split} split: {len(combined):,} total rows")
|
| 171 |
|
| 172 |
+
ds = DatasetDict(ds_dict).shuffle(seed=108)
|
| 173 |
|
| 174 |
if max_train_samples is not None and "train" in ds:
|
| 175 |
ds["train"] = ds["train"].select(range(min(max_train_samples, len(ds["train"]))))
|
src/gazet/search.py
CHANGED
|
@@ -10,6 +10,7 @@ def simple_fuzzy_search(
|
|
| 10 |
path: str,
|
| 11 |
source: str,
|
| 12 |
place: Place,
|
|
|
|
| 13 |
extra_select: str = "",
|
| 14 |
limit: int = 5,
|
| 15 |
) -> pd.DataFrame:
|
|
@@ -21,7 +22,7 @@ def simple_fuzzy_search(
|
|
| 21 |
f"""
|
| 22 |
SELECT
|
| 23 |
id,
|
| 24 |
-
|
| 25 |
country,
|
| 26 |
subtype,
|
| 27 |
class,
|
|
@@ -29,9 +30,9 @@ def simple_fuzzy_search(
|
|
| 29 |
admin_level,
|
| 30 |
is_land,
|
| 31 |
is_territorial{extra_clause},
|
| 32 |
-
jaro_winkler_similarity(lower(
|
| 33 |
FROM read_parquet(?)
|
| 34 |
-
WHERE
|
| 35 |
ORDER BY similarity DESC, admin_level ASC
|
| 36 |
LIMIT ?
|
| 37 |
""",
|
|
@@ -70,6 +71,7 @@ def search_natural_earth(
|
|
| 70 |
NATURAL_EARTH_PATH,
|
| 71 |
"natural_earth",
|
| 72 |
place,
|
|
|
|
| 73 |
limit=limit,
|
| 74 |
)
|
| 75 |
|
|
|
|
| 10 |
path: str,
|
| 11 |
source: str,
|
| 12 |
place: Place,
|
| 13 |
+
name_expr: str = 'names.common.en',
|
| 14 |
extra_select: str = "",
|
| 15 |
limit: int = 5,
|
| 16 |
) -> pd.DataFrame:
|
|
|
|
| 22 |
f"""
|
| 23 |
SELECT
|
| 24 |
id,
|
| 25 |
+
{name_expr} AS name,
|
| 26 |
country,
|
| 27 |
subtype,
|
| 28 |
class,
|
|
|
|
| 30 |
admin_level,
|
| 31 |
is_land,
|
| 32 |
is_territorial{extra_clause},
|
| 33 |
+
jaro_winkler_similarity(lower({name_expr}), lower(?)) AS similarity
|
| 34 |
FROM read_parquet(?)
|
| 35 |
+
WHERE {name_expr} IS NOT NULL AND trim({name_expr}) != ''
|
| 36 |
ORDER BY similarity DESC, admin_level ASC
|
| 37 |
LIMIT ?
|
| 38 |
""",
|
|
|
|
| 71 |
NATURAL_EARTH_PATH,
|
| 72 |
"natural_earth",
|
| 73 |
place,
|
| 74 |
+
name_expr='names.primary',
|
| 75 |
limit=limit,
|
| 76 |
)
|
| 77 |
|