jampuramprem commited on
Commit
74e7a0b
Β·
1 Parent(s): 1b91895

Make torch import optional for CPU-only Space deployment

Browse files
Files changed (1) hide show
  1. server/AxiomForgeAI_environment.py +6 -2
server/AxiomForgeAI_environment.py CHANGED
@@ -46,7 +46,6 @@ from pathlib import Path
46
  from typing import Any, Dict, List, Optional
47
  from uuid import uuid4
48
 
49
- import torch
50
  from openenv.core.env_server.interfaces import Environment
51
  from openenv.core.env_server.types import State
52
 
@@ -59,12 +58,14 @@ except ImportError:
59
  # ── Heavy RL imports β€” fail gracefully so openenv validate passes even when
60
  # the ML stack is not installed (e.g. lightweight CI / schema validation).
61
  try:
 
62
  from src.rl.math_environment_curriculum import CurriculumMathEnvironment
63
  from src.rl.prm_scorer import ProcessRewardScorer
64
  from src.sft.solution_format import extract_final_answer_numeric_str
65
 
66
  _RL_AVAILABLE = True
67
  except Exception as _rl_import_err: # pragma: no cover
 
68
  _RL_AVAILABLE = False
69
  CurriculumMathEnvironment = None # type: ignore[assignment,misc]
70
  ProcessRewardScorer = None # type: ignore[assignment,misc]
@@ -133,7 +134,10 @@ class AxiomforgeaiEnvironment(Environment):
133
 
134
  self._math_env: Optional[Any] = None # CurriculumMathEnvironment or None
135
 
136
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 
 
 
137
 
138
  if not _RL_AVAILABLE:
139
  logger.warning(
 
46
  from typing import Any, Dict, List, Optional
47
  from uuid import uuid4
48
 
 
49
  from openenv.core.env_server.interfaces import Environment
50
  from openenv.core.env_server.types import State
51
 
 
58
  # ── Heavy RL imports β€” fail gracefully so openenv validate passes even when
59
  # the ML stack is not installed (e.g. lightweight CI / schema validation).
60
  try:
61
+ import torch
62
  from src.rl.math_environment_curriculum import CurriculumMathEnvironment
63
  from src.rl.prm_scorer import ProcessRewardScorer
64
  from src.sft.solution_format import extract_final_answer_numeric_str
65
 
66
  _RL_AVAILABLE = True
67
  except Exception as _rl_import_err: # pragma: no cover
68
+ torch = None # type: ignore[assignment]
69
  _RL_AVAILABLE = False
70
  CurriculumMathEnvironment = None # type: ignore[assignment,misc]
71
  ProcessRewardScorer = None # type: ignore[assignment,misc]
 
134
 
135
  self._math_env: Optional[Any] = None # CurriculumMathEnvironment or None
136
 
137
+ if torch is not None:
138
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
139
+ else:
140
+ device = "cpu"
141
 
142
  if not _RL_AVAILABLE:
143
  logger.warning(