gblessed commited on
Commit
3fce1c5
·
verified ·
1 Parent(s): 45ebb0c

Upload inference_example.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. inference_example.py +46 -0
inference_example.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Minimal Hugging Face inference example for MultiPathFormer.
2
+
3
+ Run from a clone of the GitHub code release after installing requirements:
4
+
5
+ python weights/inference_example.py
6
+
7
+ Set `AUGMENTED_PROMPT_JSON` and `FIRST_STEP_BASELINE_JSON` to your own files.
8
+ The augmented prompt must follow the released corridor-concat feature recipe:
9
+ TX/RX position, first-step delay/power baseline, first-step std, and scene
10
+ corridor features.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import json
16
+ import os
17
+ from pathlib import Path
18
+
19
+ import numpy as np
20
+ from huggingface_hub import hf_hub_download
21
+
22
+ from multipathformer.inference import MultiPathFormerPredictor, prediction_to_rows
23
+
24
+
25
+ HF_REPO_ID = os.environ.get("HF_REPO_ID", "gblessed/multipathformer-foundation-27scenarios")
26
+ CHECKPOINT_FILENAME = "first_step_residual_corridor_concat_27scenarios_44710a4a_best_model_checkpoint.pth"
27
+ AUGMENTED_PROMPT_JSON = Path(os.environ.get("AUGMENTED_PROMPT_JSON", "examples/augmented_prompt.json"))
28
+ FIRST_STEP_BASELINE_JSON = Path(os.environ.get("FIRST_STEP_BASELINE_JSON", "examples/first_step_baseline.json"))
29
+
30
+
31
+ def main() -> None:
32
+ checkpoint_path = hf_hub_download(repo_id=HF_REPO_ID, filename=CHECKPOINT_FILENAME)
33
+ artifacts_path = hf_hub_download(repo_id=HF_REPO_ID, filename="preprocessing_artifacts.json")
34
+
35
+ augmented_prompt = np.asarray(json.loads(AUGMENTED_PROMPT_JSON.read_text(encoding="utf-8")), dtype=np.float32)
36
+ first_step_baseline = np.asarray(json.loads(FIRST_STEP_BASELINE_JSON.read_text(encoding="utf-8")), dtype=np.float32)
37
+
38
+ predictor = MultiPathFormerPredictor(checkpoint_path, artifacts_path=artifacts_path)
39
+ prediction = predictor.predict_from_augmented_prompt(augmented_prompt, first_step_baseline, max_steps=25)
40
+
41
+ for row in prediction_to_rows(prediction)[:5]:
42
+ print(row)
43
+
44
+
45
+ if __name__ == "__main__":
46
+ main()