Spaces:
Running
Running
Commit
·
5e2289d
1
Parent(s):
c978556
Workflow to ensure codebase integrity
Browse files
.github/workflows/restore_cost_benefit.yml
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Restore src/cost_benefit.py on every commit
|
2 |
+
|
3 |
+
on:
|
4 |
+
push:
|
5 |
+
branches:
|
6 |
+
- main
|
7 |
+
pull_request:
|
8 |
+
branches:
|
9 |
+
- main
|
10 |
+
|
11 |
+
jobs:
|
12 |
+
restore-file:
|
13 |
+
runs-on: ubuntu-latest
|
14 |
+
|
15 |
+
steps:
|
16 |
+
- name: Checkout repo
|
17 |
+
uses: actions/checkout@v3
|
18 |
+
|
19 |
+
- name: Recreate src/cost_benefit.py
|
20 |
+
run: |
|
21 |
+
mkdir -p src
|
22 |
+
cat <<EOF > src/cost_benefit.py
|
23 |
+
import argparse
|
24 |
+
|
25 |
+
import subprocess
|
26 |
+
|
27 |
+
import time
|
28 |
+
|
29 |
+
import requests
|
30 |
+
|
31 |
+
def detect_available_budget(runtime_env: str) -> int:
|
32 |
+
import torch
|
33 |
+
if "local" in runtime_env and torch.cuda.is_available():
|
34 |
+
total_vram_mb = torch.cuda.get_device_properties(0).total_memory // (1024 ** 2)
|
35 |
+
return min(total_vram_mb, 100)
|
36 |
+
else:
|
37 |
+
return 100
|
38 |
+
|
39 |
+
def get_best_model(runtime_env: str, use_local_only=False, use_api_only=False) -> dict:
|
40 |
+
static_costs = {
|
41 |
+
"llama3.2": {"size": 20, "token_cost": 0.0001, "tokens_sec": 30, "type": "local"},
|
42 |
+
"mistral": {"size": 40, "token_cost": 0.0002, "tokens_sec": 50, "type": "local"},
|
43 |
+
"gemini-2.0-flash": {"size": 60, "token_cost": 0.0005, "tokens_sec": 60, "type": "api"},
|
44 |
+
"gemini-2.5-pro-preview-03-25": {"size": 80, "token_cost": 0.002, "tokens_sec": 45, "type": "api"}
|
45 |
+
}
|
46 |
+
|
47 |
+
def detect_available_budget(runtime_env: str) -> int:
|
48 |
+
import torch
|
49 |
+
if "local" in runtime_env and torch.cuda.is_available():
|
50 |
+
total_vram_mb = torch.cuda.get_device_properties(0).total_memory // (1024 ** 2)
|
51 |
+
return min(total_vram_mb, 100)
|
52 |
+
else:
|
53 |
+
return 100
|
54 |
+
|
55 |
+
budget = detect_available_budget(runtime_env)
|
56 |
+
|
57 |
+
best_model = None
|
58 |
+
best_speed = -1
|
59 |
+
|
60 |
+
for model, info in static_costs.items():
|
61 |
+
if info["size"] > budget:
|
62 |
+
continue
|
63 |
+
if use_local_only and info["type"] != "local":
|
64 |
+
continue
|
65 |
+
if use_api_only and info["type"] != "api":
|
66 |
+
continue
|
67 |
+
if info["tokens_sec"] > best_speed:
|
68 |
+
best_model = model
|
69 |
+
best_speed = info["tokens_sec"]
|
70 |
+
|
71 |
+
if not best_model:
|
72 |
+
return {
|
73 |
+
"model": "llama3.2",
|
74 |
+
"token_cost": static_costs["llama3.2"]["token_cost"],
|
75 |
+
"tokens_sec": static_costs["llama3.2"]["tokens_sec"],
|
76 |
+
"note": "Defaulted due to no models fitting filters"
|
77 |
+
}
|
78 |
+
|
79 |
+
return {
|
80 |
+
"model": best_model,
|
81 |
+
"token_cost": static_costs[best_model]["token_cost"],
|
82 |
+
"tokens_sec": static_costs[best_model]["tokens_sec"]
|
83 |
+
}
|
84 |
+
EOF
|
85 |
+
|
86 |
+
- name: Commit and push if src/cost_benefit.py changed
|
87 |
+
run: |
|
88 |
+
git config user.name "github-actions"
|
89 |
+
git config user.email "github-actions@github.com"
|
90 |
+
|
91 |
+
if ! git diff --quiet src/cost_benefit.py; then
|
92 |
+
git add src/cost_benefit.py
|
93 |
+
git commit -m "Auto-restore src/cost_benefit.py"
|
94 |
+
git push
|
95 |
+
else
|
96 |
+
echo "No changes to src/cost_benefit.py"
|
97 |
+
fi
|