Spaces:
Sleeping
Sleeping
MoE .to(cuda) on xlarge (bf16 fits 96GB)
Browse files178 unmodified lines179180181182183184185186187188189190191192193194195196197178 unmodified linesdef ensure_cuda_attached(self) -> None:"""Move the loaded pipeline to GPU. MUST be called from inside @spaces.GPU.On MoE cards we use accelerate's model_cpu_offload hooks so the two14B transformers fit on the 48 GB `large` slice. On single-transformercards we just `.to(device)`. Idempotent — re-entry from a warm workeris a no-op."""if self.cuda_attached:returnimport torchbackend = detect()if self.card.is_moe and torch.cuda.is_available():self.pipe.enable_model_cpu_offload()else:self.pipe.to(backend.device)self.cuda_attached = Truedef configure_preset(self, preset: Preset) -> PresetKwargs:178 unmodified lines179180181182183184185186187188189190191192193194195196197198199200201178 unmodified linesdef ensure_cuda_attached(self) -> None:"""Move the loaded pipeline to GPU. MUST be called from inside @spaces.GPU.Decision: bf16 everywhere, MoE on the 96 GB `xlarge` slice — so the ~70 GBMoE FITS VRAM and we `.to(cuda)` it fully (no layer streaming). Fallback:if `.to(cuda)` OOMs (e.g. a MoE accidentally placed on the 48 GB `large`slice), stream layers via `enable_model_cpu_offload()`. Idempotent."""if self.cuda_attached:returnimport torchbackend = detect()try:self.pipe.to(backend.device)except Exception as e: # OOM / placement failureif self.card.is_moe and torch.cuda.is_available():print(f"=== .to(cuda) failed ({type(e).__name__}); MoE cpu_offload fallback ===", flush=True)self.pipe.enable_model_cpu_offload()else:raiseself.cuda_attached = Truedef configure_preset(self, preset: Preset) -> PresetKwargs:
pipelines/handle.py+11-7