harshil-21 commited on
Commit
e9b675c
·
1 Parent(s): 5e2289d

Workflow to ensure codebase integrity

Browse files
.github/workflows/restore_cost_benefit.yml CHANGED
@@ -1,97 +1,89 @@
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
 
1
+ # .github/workflows/restore_cost_benefit.yml
2
+ name: Restore src/cost_benefit.py
3
 
4
  on:
5
  push:
6
+ branches: [main]
 
7
  pull_request:
8
+ branches: [main]
 
9
 
10
  jobs:
11
+ restore:
12
  runs-on: ubuntu-latest
13
+ # allow the GITHUB_TOKEN to push a commit back
14
+ permissions:
15
+ contents: write
16
 
17
  steps:
18
+ - name: Checkout repository
19
  uses: actions/checkout@v3
20
+ with:
21
+ # you need the token available for the later push
22
+ token: ${{ secrets.GITHUB_TOKEN }}
23
 
24
  - name: Recreate src/cost_benefit.py
25
  run: |
26
  mkdir -p src
27
+ cat > src/cost_benefit.py <<'PY'
28
+ import argparse
29
+ import subprocess
30
+ import time
31
+ import requests
32
+
33
+ def detect_available_budget(runtime_env: str) -> int:
34
+ """
35
+ Return an approximate VRAM‑based budget (MB) when running locally,
36
+ else default to 100.
37
+ """
38
+ import torch
39
+ if "local" in runtime_env and torch.cuda.is_available():
40
+ total_vram_mb = torch.cuda.get_device_properties(0).total_memory // (1024 ** 2)
41
+ return min(total_vram_mb, 100)
42
+ return 100
43
+
44
+ def get_best_model(runtime_env: str, *, use_local_only: bool = False, use_api_only: bool = False) -> dict:
45
+ """
46
+ Pick the fastest model that fits in the detected budget while
47
+ respecting the locality filters.
48
+ """
49
+ static_costs = {
50
+ "llama3.2": {"size": 20, "token_cost": 0.0001, "tokens_sec": 30, "type": "local"},
51
+ "mistral": {"size": 40, "token_cost": 0.0002, "tokens_sec": 50, "type": "local"},
52
+ "gemini-2.0-flash": {"size": 60, "token_cost": 0.0005, "tokens_sec": 60, "type": "api"},
53
+ "gemini-2.5-pro-preview-03-25": {"size": 80, "token_cost": 0.002 , "tokens_sec": 45, "type": "api"},
54
+ }
55
+
56
+ budget = detect_available_budget(runtime_env)
57
+ best_model, best_speed = None, -1
58
+
59
+ for model, info in static_costs.items():
60
+ if info["size"] > budget:
61
+ continue
62
+ if use_local_only and info["type"] != "local":
63
+ continue
64
+ if use_api_only and info["type"] != "api":
65
+ continue
66
+ if info["tokens_sec"] > best_speed:
67
+ best_model, best_speed = model, info["tokens_sec"]
68
+
69
+ chosen = best_model or "llama3.2" # sensible default
70
+ return {
71
+ "model": chosen,
72
+ "token_cost": static_costs[chosen]["token_cost"],
73
+ "tokens_sec": static_costs[chosen]["tokens_sec"],
74
+ "note": None if best_model else "Defaulted because no model met the constraints",
75
+ }
76
+ PY
77
+
78
+ # only push when the workflow is triggered by a direct push to main
79
+ - name: Commit & push if the file changed
80
+ if: github.event_name == 'push' && github.ref == 'refs/heads/main'
 
 
 
 
 
 
 
 
 
 
 
81
  run: |
82
+ git config user.name "github-actions"
83
  git config user.email "github-actions@github.com"
 
84
  if ! git diff --quiet src/cost_benefit.py; then
85
+ git add src/cost_benefit.py
86
+ git commit -m "chore(ci): auto‑restore src/cost_benefit.py [skip ci]"
87
+ git push origin HEAD:main
88
  else
89
+ echo "No changes detected"