Benjamin Auquite commited on
Commit
156a268
·
verified ·
1 Parent(s): 4a4c126

Upload src/trellis2/pipelines/trellis2_image_to_3d.py with huggingface_hub

Browse files
src/trellis2/pipelines/trellis2_image_to_3d.py CHANGED
@@ -66,6 +66,7 @@ class Trellis2ImageTo3DPipeline(Pipeline):
66
  'alpha': slice(5, 6),
67
  }
68
  self._device = 'cpu'
 
69
 
70
  @staticmethod
71
  def from_pretrained(path: str) -> "Trellis2ImageTo3DPipeline":
@@ -104,6 +105,7 @@ class Trellis2ImageTo3DPipeline(Pipeline):
104
  'alpha': slice(5, 6),
105
  }
106
  new_pipeline._device = 'cpu'
 
107
 
108
  return new_pipeline
109
 
@@ -163,10 +165,25 @@ class Trellis2ImageTo3DPipeline(Pipeline):
163
  dict: The conditioning information
164
  """
165
  self.image_cond_model.image_size = resolution
166
- if self.low_vram:
 
 
167
  self.image_cond_model.to(self.device)
168
- cond = self.image_cond_model(image)
169
- if self.low_vram:
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  self.image_cond_model.cpu()
171
  if not include_neg_cond:
172
  return {'cond': cond}
 
66
  'alpha': slice(5, 6),
67
  }
68
  self._device = 'cpu'
69
+ self._image_cond_force_cpu = False
70
 
71
  @staticmethod
72
  def from_pretrained(path: str) -> "Trellis2ImageTo3DPipeline":
 
105
  'alpha': slice(5, 6),
106
  }
107
  new_pipeline._device = 'cpu'
108
+ new_pipeline._image_cond_force_cpu = False
109
 
110
  return new_pipeline
111
 
 
165
  dict: The conditioning information
166
  """
167
  self.image_cond_model.image_size = resolution
168
+ if self._image_cond_force_cpu:
169
+ self.image_cond_model.cpu()
170
+ elif self.low_vram:
171
  self.image_cond_model.to(self.device)
172
+
173
+ try:
174
+ cond = self.image_cond_model(image)
175
+ except RuntimeError as exc:
176
+ kernel_image_error = "no kernel image is available for execution on the device" in str(exc).lower()
177
+ if self._image_cond_force_cpu or not kernel_image_error:
178
+ raise
179
+ self._image_cond_force_cpu = True
180
+ self.image_cond_model.cpu()
181
+ cond = self.image_cond_model(image)
182
+
183
+ if cond.device != self.device:
184
+ cond = cond.to(self.device)
185
+
186
+ if self.low_vram or self._image_cond_force_cpu:
187
  self.image_cond_model.cpu()
188
  if not include_neg_cond:
189
  return {'cond': cond}