Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[issue-22] Work with Mac M1/M2/M3 #152

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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