Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__/
.DS_Store
*.egg-info/
shap_e_model_cache/
9 changes: 8 additions & 1 deletion shap_e/diffusion/gaussian_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import torch as th
import yaml

is_mps = th.backends.mps.is_available()


def diffusion_from_config(config: Union[str, Dict[str, Any]]) -> "GaussianDiffusion":
if isinstance(config, str):
Expand Down Expand Up @@ -1065,7 +1067,12 @@ def _extract_into_tensor(arr, timesteps, broadcast_shape):
dimension equal to the length of timesteps.
:return: a tensor of shape [batch_size, 1, ...] where the shape has K dims.
"""
res = th.from_numpy(arr).to(device=timesteps.device)[timesteps].float()
res = None
if is_mps:
res = th.from_numpy(arr.astype(np.float32)).to(device=timesteps.device)[timesteps].float()
else:
res = th.from_numpy(arr).to(device=timesteps.device)[timesteps].float()

while len(res.shape) < len(broadcast_shape):
res = res[..., None]
return res + th.zeros(broadcast_shape, device=timesteps.device)
Expand Down
Loading