Silvio Galesso commited on
Commit
ca201a9
·
1 Parent(s): efa506a

appearance fixes

Browse files
Files changed (2) hide show
  1. app2.py +7 -5
  2. orbis2_app_engine.py +28 -34
app2.py CHANGED
@@ -946,12 +946,14 @@ def run_rollout(video_path: str, gen_seconds: float, l1_steps: int, l2_steps: in
946
  traj_path = job / "trajectory.npy"
947
  np.save(traj_path, trajectory_to_model_frame(trajectory))
948
 
949
- # First request in this worker moves the model to CUDA and compiles it;
950
- # every later request just reuses that already-ready model (see
 
 
951
  # orbis2_app_engine.py).
952
- print("[load] ensure_ready: moving model to GPU / compiling if needed…")
953
- ENGINE.ensure_ready(device="cuda", compile=False,
954
- compile_artifacts=str(EXP_DIR / "compile_cache.pkl"))
955
 
956
  say(0.10, "🚗 Rolling out…")
957
 
 
946
  traj_path = job / "trajectory.npy"
947
  np.save(traj_path, trajectory_to_model_frame(trajectory))
948
 
949
+ # First request in this worker moves the model to CUDA, then compiles it only if
950
+ # the pre-compiled artifacts below can be loaded -- otherwise it runs eagerly
951
+ # rather than paying for a from-scratch compile live in a request. Every later
952
+ # request just reuses that already-ready (compiled or eager) model (see
953
  # orbis2_app_engine.py).
954
+ print("[load] ensure_ready: moving model to GPU, compiling only if cached artifacts load…")
955
+ ENGINE.ensure_ready(device="cuda", compile=True,
956
+ compile_artifacts=str(EXP_DIR / "checkpoints" / "compile_cache.pkl"))
957
 
958
  say(0.10, "🚗 Rolling out…")
959
 
orbis2_app_engine.py CHANGED
@@ -118,8 +118,6 @@ class RolloutEngine:
118
  self.model = None
119
  self._ready = False
120
  self._lock = threading.Lock()
121
- self._compile_artifacts = None
122
- self._artifacts_saved = False
123
 
124
  def load(self):
125
  """CPU-only one-time setup: read the config, build the model, load the
@@ -178,12 +176,15 @@ class RolloutEngine:
178
 
179
  def ensure_ready(self, device="cuda", compile=True, compile_mode="reduce-overhead",
180
  compile_artifacts=None, speed_scale=1.0, yaw_rate_scale=1.0):
181
- """Move the model to `device` and wrap it with torch.compile, exactly once.
 
 
 
182
  Safe to call on every request: after the first call this is a no-op, because
183
- the model lives in this persistent process and keeps its GPU/compiled state
184
- between calls."""
185
  if self._ready:
186
- print("[compile] model already on-device and compiled from a prior request -- reusing it as-is.")
187
  return self.model
188
 
189
  with self._lock:
@@ -192,7 +193,25 @@ class RolloutEngine:
192
 
193
  model = self.model.to(device)
194
 
195
- if compile:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  def _maybe_compile(module, attr):
197
  net = getattr(module, attr, None)
198
  if net is not None:
@@ -205,29 +224,12 @@ class RolloutEngine:
205
  if l2_predictor is not None:
206
  _maybe_compile(l2_predictor, "ema_vit")
207
 
208
- if compile_artifacts:
209
- if os.path.exists(compile_artifacts):
210
- with open(compile_artifacts, "rb") as f:
211
- torch.compiler.load_cache_artifacts(f.read())
212
- print(f"[compile] loaded cached compile artifacts from {compile_artifacts!r} "
213
- "-- first call reuses these instead of tracing from scratch.")
214
- logger.info(f"Loaded compile artifacts from {compile_artifacts!r}")
215
- else:
216
- print(f"[compile] no compile artifacts found at {compile_artifacts!r} "
217
- "-- compiling from scratch; will save artifacts after the first rollout.")
218
- logger.info(
219
- f"Compile artifacts not found at {compile_artifacts!r}; "
220
- "will save after the first rollout."
221
- )
222
- else:
223
- print("[compile] no compile_artifacts path given -- compiling from scratch, nothing cached to disk.")
224
- self._compile_artifacts = compile_artifacts
225
-
226
  maybe_apply_condition_preprocessor_scales(model, speed_scale, yaw_rate_scale)
227
 
228
  self.model = model
229
  self._ready = True
230
- logger.info(f"Model moved to {device} and ready -- subsequent requests reuse this instance.")
 
231
 
232
  return self.model
233
 
@@ -368,14 +370,6 @@ class RolloutEngine:
368
  if device.startswith("cuda"):
369
  logger.info(f"Max memory: {torch.cuda.max_memory_allocated() / 1024**3:.02f} GB")
370
 
371
- if self._compile_artifacts and not self._artifacts_saved and not os.path.exists(self._compile_artifacts):
372
- artifacts = torch.compiler.save_cache_artifacts()
373
- if artifacts is not None:
374
- with open(self._compile_artifacts, "wb") as f:
375
- f.write(artifacts[0])
376
- logger.info(f"Saved compile artifacts to {self._compile_artifacts!r}")
377
- self._artifacts_saved = True
378
-
379
 
380
  _engine = None
381
  _engine_lock = threading.Lock()
 
118
  self.model = None
119
  self._ready = False
120
  self._lock = threading.Lock()
 
 
121
 
122
  def load(self):
123
  """CPU-only one-time setup: read the config, build the model, load the
 
176
 
177
  def ensure_ready(self, device="cuda", compile=True, compile_mode="reduce-overhead",
178
  compile_artifacts=None, speed_scale=1.0, yaw_rate_scale=1.0):
179
+ """Move the model to `device` and, only if a matching pre-compiled artifacts
180
+ file is available, wrap it with torch.compile and warm-start from that cache.
181
+ Otherwise runs eagerly -- this never compiles from scratch live in a request,
182
+ since tracing/codegen from nothing is far too slow to pay on a real request.
183
  Safe to call on every request: after the first call this is a no-op, because
184
+ the model lives in this persistent process and keeps its GPU/compiled-or-eager
185
+ state between calls."""
186
  if self._ready:
187
+ print("[compile] model already on-device from a prior request -- reusing it as-is.")
188
  return self.model
189
 
190
  with self._lock:
 
193
 
194
  model = self.model.to(device)
195
 
196
+ use_compile = False
197
+ if compile and compile_artifacts and os.path.exists(compile_artifacts):
198
+ try:
199
+ with open(compile_artifacts, "rb") as f:
200
+ torch.compiler.load_cache_artifacts(f.read())
201
+ use_compile = True
202
+ print(f"[compile] loaded cached compile artifacts from {compile_artifacts!r} "
203
+ "-- compiling with these instead of tracing from scratch.")
204
+ logger.info(f"Loaded compile artifacts from {compile_artifacts!r}")
205
+ except Exception as e:
206
+ print(f"[compile] failed to load compile artifacts from {compile_artifacts!r} "
207
+ f"({e!r}) -- running eagerly, no torch.compile.")
208
+ elif compile and compile_artifacts:
209
+ print(f"[compile] no compile artifacts found at {compile_artifacts!r} "
210
+ "-- running eagerly, no torch.compile (will not compile from scratch).")
211
+ elif compile:
212
+ print("[compile] no compile_artifacts path given -- running eagerly, no torch.compile.")
213
+
214
+ if use_compile:
215
  def _maybe_compile(module, attr):
216
  net = getattr(module, attr, None)
217
  if net is not None:
 
224
  if l2_predictor is not None:
225
  _maybe_compile(l2_predictor, "ema_vit")
226
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  maybe_apply_condition_preprocessor_scales(model, speed_scale, yaw_rate_scale)
228
 
229
  self.model = model
230
  self._ready = True
231
+ logger.info(f"Model moved to {device} and ready "
232
+ f"({'compiled' if use_compile else 'eager'}) -- subsequent requests reuse this instance.")
233
 
234
  return self.model
235
 
 
370
  if device.startswith("cuda"):
371
  logger.info(f"Max memory: {torch.cuda.max_memory_allocated() / 1024**3:.02f} GB")
372
 
 
 
 
 
 
 
 
 
373
 
374
  _engine = None
375
  _engine_lock = threading.Lock()