ArshPathan commited on
Commit
5c07aa1
·
1 Parent(s): 8315049

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. inference.py +34 -6
inference.py CHANGED
@@ -412,27 +412,53 @@ async def run_episode(env: MaterialForgeEnv, client: OpenAI, task: Dict) -> floa
412
 
413
  async def main():
414
  """Main benchmark entry point."""
415
- api_url = os.getenv("API_BASE_URL")
416
- api_key = os.getenv("API_KEY")
417
 
418
  if not (api_url and api_key):
419
- print("[DEBUG] Missing required LiteLLM environment variables.", flush=True)
 
420
  for task in TASKS:
421
  log_start(task["name"], BENCHMARK_ID, MODEL_NAME)
422
  log_end(False, 0, MIN_TASK_SCORE, [])
423
  return
424
 
 
425
  client = OpenAI(base_url=api_url, api_key=api_key)
426
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
427
  try:
428
  # Initialize environment connection
429
  if SPACE_URL:
 
430
  env = MaterialForgeEnv(base_url=SPACE_URL)
431
  await env.connect()
432
- elif os.getenv("USE_LOCALHOST"):
433
- env = MaterialForgeEnv(base_url="http://localhost:8000")
 
 
 
 
 
434
  await env.connect()
435
  else:
 
436
  env = await MaterialForgeEnv.from_docker_image(IMAGE_NAME)
437
 
438
  # Run tasks
@@ -443,7 +469,9 @@ async def main():
443
  print(f"\n[SUMMARY] Avg Score: {sum(scores)/len(scores):.3f}", flush=True)
444
 
445
  except Exception as e:
446
- print(f"[DEBUG] Runtime initialization failed: {e}", flush=True)
 
 
447
  finally:
448
  try:
449
  await env.close()
 
412
 
413
  async def main():
414
  """Main benchmark entry point."""
415
+ api_url = os.environ.get("API_BASE_URL")
416
+ api_key = os.environ.get("API_KEY")
417
 
418
  if not (api_url and api_key):
419
+ print("[ERROR] Missing required API_BASE_URL or API_KEY environment variables.", flush=True)
420
+ # Still output start/end for the validator to see progress if applicable
421
  for task in TASKS:
422
  log_start(task["name"], BENCHMARK_ID, MODEL_NAME)
423
  log_end(False, 0, MIN_TASK_SCORE, [])
424
  return
425
 
426
+ print(f"[DEBUG] Initializing OpenAI client with base_url={api_url}", flush=True)
427
  client = OpenAI(base_url=api_url, api_key=api_key)
428
 
429
+ # Warmup call: critical for the validator to see API traffic early
430
+ try:
431
+ print("[DEBUG] Performing LLM warmup call...", flush=True)
432
+ warmup = client.chat.completions.create(
433
+ model=MODEL_NAME,
434
+ messages=[
435
+ {"role": "system", "content": "You are a material science assistant."},
436
+ {"role": "user", "content": "Hello. Response with 'OK'."},
437
+ ],
438
+ temperature=0.0,
439
+ max_tokens=8,
440
+ )
441
+ print(f"[DEBUG] LLM warmup success: {warmup.choices[0].message.content.strip()}", flush=True)
442
+ except Exception as exc:
443
+ print(f"[ERROR] LLM warmup failed: {exc}", flush=True)
444
+ # We continue anyway, as the actual tasks might still work or provide more info
445
+
446
  try:
447
  # Initialize environment connection
448
  if SPACE_URL:
449
+ print(f"[DEBUG] Connecting to remote environment at {SPACE_URL}", flush=True)
450
  env = MaterialForgeEnv(base_url=SPACE_URL)
451
  await env.connect()
452
+ elif os.getenv("USE_LOCALHOST") or os.getenv("PORT"):
453
+ # If PORT is set (common in container environments), default to localhost
454
+ host = os.getenv("HOST", "localhost")
455
+ port = os.getenv("PORT", "8000")
456
+ url = f"http://{host}:{port}"
457
+ print(f"[DEBUG] Connecting to local environment at {url}", flush=True)
458
+ env = MaterialForgeEnv(base_url=url)
459
  await env.connect()
460
  else:
461
+ print(f"[DEBUG] Starting environment from Docker image: {IMAGE_NAME}", flush=True)
462
  env = await MaterialForgeEnv.from_docker_image(IMAGE_NAME)
463
 
464
  # Run tasks
 
469
  print(f"\n[SUMMARY] Avg Score: {sum(scores)/len(scores):.3f}", flush=True)
470
 
471
  except Exception as e:
472
+ print(f"[ERROR] Runtime initialization failed: {e}", flush=True)
473
+ import traceback
474
+ traceback.print_exc()
475
  finally:
476
  try:
477
  await env.close()