Skip to content

Commit eae6e40

Browse files
authored
api: get_info reports the LoRA rank the model was created with (#453)
1 parent 3784d16 commit eae6e40

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎src/server/api_server.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,12 +1155,14 @@ async def get_info(req: GetInfoRequest):
11551155
if not model_name:
11561156
raise HTTPException(status_code=404, detail="No base model is configured")
11571157
# SDK compatibility: the public client currently expects LoRA-shaped training metadata,
1158-
# even when this process is running a full fine-tuning worker.
1158+
# even when this process is running a full fine-tuning worker. A LoRA job reports the
1159+
# rank it was created with; a full fine-tune has none, so it keeps the placeholder 16.
1160+
lora_rank = meta.lora_config.rank if meta is not None and meta.fine_tuning_type == "lora" else 16
11591161
result = {
11601162
"model_data": {"arch": "unknown", "model_name": model_name, "tokenizer_id": model_name},
11611163
"model_id": model_id or "model-live-123",
11621164
"is_lora": True,
1163-
"lora_rank": 16,
1165+
"lora_rank": lora_rank,
11641166
"model_name": model_name,
11651167
"type": "get_info",
11661168
}

‎tests/test_api_server_paths.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,23 @@ def test_get_info_prefers_the_models_own_base_model(self) -> None:
5555
self.assertEqual(via_sampler_ref["model_name"], "google/gemma-4-e2b")
5656
self.assertEqual(unknown["model_name"], "Qwen/Qwen2.5-0.5B")
5757

58+
def test_get_info_reports_the_lora_rank_the_job_was_created_with(self) -> None:
59+
lora = json.dumps({"base_model": "google/gemma-4-e2b", "lora_config": {"rank": 32}})
60+
full = json.dumps({"base_model": "google/gemma-4-e2b", "fine_tuning_type": "full", "lora_config": {"rank": 32}})
61+
asyncio.run(api_server.state.set_value("open_rl:model_meta:model-r32", lora))
62+
asyncio.run(api_server.state.set_value("open_rl:model_meta:model-full", full))
63+
with patch.dict(os.environ, {"BASE_MODEL": "Qwen/Qwen2.5-0.5B"}, clear=True):
64+
info = self.post("get_info", {"model_id": "model-r32"}).json()
65+
via_sampler_ref = self.post("get_info", {"model_id": "tinker://model-r32/sampler_weights/sampler-1"}).json()
66+
full_info = self.post("get_info", {"model_id": "model-full"}).json()
67+
unknown = self.post("get_info", {"model_id": "model-unknown"}).json()
68+
69+
self.assertEqual(info["lora_rank"], 32)
70+
self.assertEqual(via_sampler_ref["lora_rank"], 32)
71+
# A full fine-tune has no adapter; the SDK still expects a rank, so it gets the default.
72+
self.assertEqual(full_info["lora_rank"], 16)
73+
self.assertEqual(unknown["lora_rank"], 16)
74+
5875
def test_get_info_404s_without_base_model_env(self) -> None:
5976
with patch.dict(os.environ, {}, clear=True):
6077
response = self.post("get_info", {"model_id": "model-a"})

0 commit comments

Comments
 (0)