Factor Studios commited on
Commit
e7b0695
·
verified ·
1 Parent(s): 0e61fb3

Update torch_vgpu.py

Browse files
Files changed (1) hide show
  1. torch_vgpu.py +0 -49
torch_vgpu.py CHANGED
@@ -294,55 +294,6 @@ def create_compatible_device_map(device_spec):
294
  return "cpu"
295
  return device_spec
296
 
297
- def load_model_to_vgpu(model_name_or_path, vgpu_device=None, **kwargs):
298
- """
299
- Load a Transformers model and move it to vGPU after loading.
300
- This avoids the isinstance() issues during model loading.
301
- """
302
- from transformers import AutoModelForCausalLM, AutoTokenizer
303
-
304
- # Remove device-related kwargs to avoid conflicts
305
- device_map = kwargs.pop('device_map', None)
306
- device = kwargs.pop('device', None)
307
-
308
- # Load model on CPU first
309
- print(f"Loading {model_name_or_path} on CPU first...")
310
- model = AutoModelForCausalLM.from_pretrained(
311
- model_name_or_path,
312
- device_map="cpu",
313
- **kwargs
314
- )
315
-
316
- # Get or create vGPU device
317
- if vgpu_device is None:
318
- if not VGPUDevice._VGPU_INSTANCES:
319
- vgpu_device = VGPUDevice()
320
- else:
321
- vgpu_device = next(iter(VGPUDevice._VGPU_INSTANCES.values()))
322
-
323
- # Move model to vGPU (this will be handled by our custom tensor class)
324
- print(f"Moving model to {vgpu_device}...")
325
- # Note: The actual movement is handled by our VGPUTensor class
326
- # For now, we'll keep it on CPU but track it as vGPU
327
- model._vgpu_device = vgpu_device
328
-
329
- return model
330
-
331
- def create_vgpu_pipeline(model_name_or_path, task="text-generation", vgpu_device=None, **kwargs):
332
- """
333
- Create a Transformers pipeline that uses vGPU.
334
- This wrapper handles the compatibility issues.
335
- """
336
- from transformers import pipeline
337
-
338
- # Load model using our compatible method
339
- model = load_model_to_vgpu(model_name_or_path, vgpu_device, **kwargs)
340
-
341
- # Create pipeline with the loaded model
342
- pipe = pipeline(task, model=model, **kwargs)
343
-
344
- return pipe
345
-
346
  # Create a proper device class that extends torch.device behavior
347
  class VGPUDeviceWrapper(torch.device):
348
  """Extended device class that handles vGPU devices while maintaining torch.device compatibility"""
 
294
  return "cpu"
295
  return device_spec
296
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
  # Create a proper device class that extends torch.device behavior
298
  class VGPUDeviceWrapper(torch.device):
299
  """Extended device class that handles vGPU devices while maintaining torch.device compatibility"""