-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremote_client.py
More file actions
68 lines (59 loc) · 2.26 KB
/
Copy pathremote_client.py
File metadata and controls
68 lines (59 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import requests
import config
import time
def sync_remote_model(local_filename):
"""
The 'Translator' Function.
1. Looks up the local filename in config.py
2. Finds the matching Remote ID.
3. Tells the RunPod Manager to load it.
"""
if not config.USE_RUNPOD:
print("[REMOTE] Remote mode is DISABLED in config.")
return False
# 1. Translate
remote_id = config.MODEL_MAP.get(local_filename)
if not remote_id:
print(f"[REMOTE] ⚠️ No translation found for '{local_filename}'.")
print(f" Using default: {config.DEFAULT_REMOTE_MODEL}")
remote_id = config.DEFAULT_REMOTE_MODEL
print(f"\n[REMOTE] 📡 Connecting to RunPod...")
print(f"[REMOTE] 🔄 Requesting Switch: {local_filename} -> {remote_id}")
# 2. Send Command to Manager
manager_url = f"{config.RUNPOD_BASE_URL}/manager/load_model"
try:
# We start by checking if the server is even there
response = requests.post(
manager_url,
json={"model_id": remote_id},
timeout=10
)
if response.status_code == 200:
data = response.json()
print(f"[REMOTE] ✅ SUCCESS: {data.get('message')}")
print(f"[REMOTE] ⏳ Waiting for model to load (approx 30s)...")
_wait_for_server_ready()
return True
else:
print(f"[REMOTE] ❌ ERROR: Server returned {response.status_code}")
return False
except requests.exceptions.RequestException as e:
print(f"[REMOTE] ❌ CONNECTION FAILED: Is the Pod running?")
print(f" URL: {manager_url}")
return False
def _wait_for_server_ready():
"""Pings the chat endpoint until it replies, confirming model is loaded."""
url = f"{config.RUNPOD_BASE_URL}/v1/models"
for i in range(12): # Try for 60 seconds
try:
requests.get(url, timeout=2)
print("[REMOTE] 🚀 Server is READY!")
return
except:
time.sleep(5)
print(".", end="", flush=True)
print("\n[REMOTE] ⚠️ Server is taking a long time. Proceeding anyway...")
# Test block
if __name__ == "__main__":
test_model = "Qwen3-8B-Q5_K_M.gguf"
sync_remote_model(test_model)