jmullings commited on
Commit
3ef9957
·
1 Parent(s): 80218b7

Base application

Browse files
Files changed (1) hide show
  1. src/submission/submit.py +36 -36
src/submission/submit.py CHANGED
@@ -1,9 +1,9 @@
1
  import json
2
  import os
3
- import queue
4
  import re
5
  import sys
6
  import threading
 
7
  import traceback
8
  from datetime import datetime, timezone
9
 
@@ -143,13 +143,12 @@ def _save_cert(model_id: str, revision: str, cert: dict) -> str:
143
  return out_path
144
 
145
 
 
146
  @gpu_decorator(duration=120)
147
- def execute_direct_xray_audit(model_id: str, revision: str = "main", trust_remote_code: bool = False, progress_callback=None) -> dict:
148
  now_str = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S")
149
 
150
- if progress_callback:
151
- progress_callback(f"Verifying '{model_id}' on Hugging Face Hub...")
152
- print(f"[LLM-X-RAY] Verifying model '{model_id}'...", flush=True)
153
 
154
  try:
155
  feas = check_feasibility(model_id, revision, TOKEN, MAX_AUDIT_PARAMS_BILLION, trust_remote_code=trust_remote_code)
@@ -163,13 +162,14 @@ def execute_direct_xray_audit(model_id: str, revision: str = "main", trust_remot
163
  _save_cert(model_id, revision, cert)
164
  return cert
165
 
 
166
  result = run_full_audit(
167
  model_id=model_id,
168
  revision=revision,
169
- device=AUDIT_DEVICE,
170
  token=TOKEN,
171
  trust_remote_code=trust_remote_code,
172
- progress_callback=progress_callback,
173
  )
174
 
175
  cert = {
@@ -179,7 +179,7 @@ def execute_direct_xray_audit(model_id: str, revision: str = "main", trust_remot
179
  "model_sha": revision,
180
  "architecture": feas.architecture or "CausalLM",
181
  "params": feas.param_count_b,
182
- "precision": "bfloat16" if AUDIT_DEVICE == "cuda" else "float32",
183
  "license": "open-source",
184
  },
185
  "audited_at": now_str,
@@ -216,7 +216,7 @@ def audit_or_search_model(url_or_id: str, trust_remote_code: bool = False):
216
  )
217
  return
218
 
219
- # Check for existing cert first
220
  existing_cert = get_certificate_by_model_name(clean_model)
221
  if existing_cert and existing_cert.get("status") == "ok":
222
  yield (
@@ -227,21 +227,22 @@ def audit_or_search_model(url_or_id: str, trust_remote_code: bool = False):
227
  )
228
  return
229
 
230
- latest_msg = f"Connecting to HF Hub for <b>{clean_model}</b>..."
231
  yield (
232
- styled_loading(latest_msg, "Verifying repository and downloading model tensors..."),
233
  current_df,
234
  current_top3,
235
  current_panel,
236
  )
237
 
238
- progress_q: "queue.Queue" = queue.Queue()
239
- result_holder: dict = {}
240
 
241
  def _worker():
242
  try:
 
243
  result_holder["cert"] = execute_direct_xray_audit(
244
- clean_model, "main", trust_remote_code=trust_remote_code, progress_callback=progress_q.put
245
  )
246
  except Exception as err:
247
  traceback.print_exc()
@@ -252,32 +253,31 @@ def audit_or_search_model(url_or_id: str, trust_remote_code: bool = False):
252
  "error_message": str(err),
253
  }
254
  finally:
255
- progress_q.put(None)
256
 
257
  thread = threading.Thread(target=_worker, daemon=True)
258
  thread.start()
259
 
260
- while True:
261
- try:
262
- msg = progress_q.get(timeout=0.2)
263
- if msg is None:
264
- break
265
- latest_msg = msg
266
- yield (
267
- styled_loading(latest_msg, "Executing multi-layer operator audit. Progress streams live below."),
268
- current_df,
269
- current_top3,
270
- current_panel,
271
- )
272
- except queue.Empty:
273
- if not thread.is_alive():
274
- break
275
- yield (
276
- styled_loading(latest_msg, "Audit in progress... Please keep this page open."),
277
- current_df,
278
- current_top3,
279
- current_panel,
280
- )
281
 
282
  thread.join()
283
  cert = result_holder.get("cert", {})
 
1
  import json
2
  import os
 
3
  import re
4
  import sys
5
  import threading
6
+ import time
7
  import traceback
8
  from datetime import datetime, timezone
9
 
 
143
  return out_path
144
 
145
 
146
+ # Pure, pickleable function signature for ZeroGPU multiprocessing
147
  @gpu_decorator(duration=120)
148
+ def execute_direct_xray_audit(model_id: str, revision: str = "main", trust_remote_code: bool = False) -> dict:
149
  now_str = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S")
150
 
151
+ print(f"[LLM-X-RAY] Verifying repository metadata for '{model_id}'...", flush=True)
 
 
152
 
153
  try:
154
  feas = check_feasibility(model_id, revision, TOKEN, MAX_AUDIT_PARAMS_BILLION, trust_remote_code=trust_remote_code)
 
162
  _save_cert(model_id, revision, cert)
163
  return cert
164
 
165
+ # Run multi-layer audit (logs automatically stream to console with flush=True)
166
  result = run_full_audit(
167
  model_id=model_id,
168
  revision=revision,
169
+ device="cuda" if has_spaces else AUDIT_DEVICE,
170
  token=TOKEN,
171
  trust_remote_code=trust_remote_code,
172
+ progress_callback=None,
173
  )
174
 
175
  cert = {
 
179
  "model_sha": revision,
180
  "architecture": feas.architecture or "CausalLM",
181
  "params": feas.param_count_b,
182
+ "precision": "bfloat16" if (has_spaces or AUDIT_DEVICE == "cuda") else "float32",
183
  "license": "open-source",
184
  },
185
  "audited_at": now_str,
 
216
  )
217
  return
218
 
219
+ # Check for existing cert first (instant load)
220
  existing_cert = get_certificate_by_model_name(clean_model)
221
  if existing_cert and existing_cert.get("status") == "ok":
222
  yield (
 
227
  )
228
  return
229
 
230
+ # Initial loading feedback
231
  yield (
232
+ styled_loading(f"Connecting to HF Hub for <b>{clean_model}</b>...", "Requesting ZeroGPU slice & downloading model weights..."),
233
  current_df,
234
  current_top3,
235
  current_panel,
236
  )
237
 
238
+ result_holder = {}
239
+ done_event = threading.Event()
240
 
241
  def _worker():
242
  try:
243
+ # Arguments are pure primitives (str, str, bool) -> 100% pickleable on ZeroGPU
244
  result_holder["cert"] = execute_direct_xray_audit(
245
+ clean_model, "main", trust_remote_code=trust_remote_code
246
  )
247
  except Exception as err:
248
  traceback.print_exc()
 
253
  "error_message": str(err),
254
  }
255
  finally:
256
+ done_event.set()
257
 
258
  thread = threading.Thread(target=_worker, daemon=True)
259
  thread.start()
260
 
261
+ # Informative UI stage cycle while ZeroGPU finishes audit
262
+ stages = [
263
+ "Downloading model weights and tokenizer tensors...",
264
+ "Layer A: Performing SVD Spectral Tomography across weight tensors...",
265
+ "Layer B: Streaming activations and calculating operator covariance...",
266
+ "Layer C: Running empirical factual probe battery...",
267
+ "Finalizing operator risk and registering certificate...",
268
+ ]
269
+ stage_idx = 0
270
+
271
+ while not done_event.is_set():
272
+ current_stage = stages[min(stage_idx, len(stages) - 1)]
273
+ yield (
274
+ styled_loading(f"🔬 Auditing <b>{clean_model}</b>...", current_stage),
275
+ current_df,
276
+ current_top3,
277
+ current_panel,
278
+ )
279
+ done_event.wait(timeout=2.5)
280
+ stage_idx += 1
 
281
 
282
  thread.join()
283
  cert = result_holder.get("cert", {})