deepchem icon indicating copy to clipboard operation
deepchem copied to clipboard

GCNModel error on Macbook (Apple Silicon)

Open syedzayyan opened this issue 2 years ago • 1 comments

🐛 Bug

Any Graph Model depending on dgl does not work with my Apple Silicon without "hacking" in the dev version of deepchem

To Reproduce

import deepchem as dc
import tempfile
import os
import pandas as pd

smiles = [
    "CCN(CCSC)C(=O)N[C@@](C)(CC)C(F)(F)F",
    "CC1(C)CN(C(=O)Nc2cc3ccccc3nn2)C[C@@]2(CCOC2)O1"
]
labels = [3.112, 2.432]
df = pd.DataFrame(list(zip(smiles, labels)), columns=["smiles", "task1"])
filepath = os.path.join(tempfile.gettempdir(), 'smiles.csv')
df.to_csv(filepath)

loader = dc.data.CSVLoader(["task1"],
                           feature_field="smiles",
                           featurizer=dc.feat.MolGraphConvFeaturizer())
dataset = loader.create_dataset(filepath)

model = dc.models.torch_models.GCNModel(n_tasks = 1)
model.fit(dataset)

Steps to reproduce the behavior:

  1. pip install --pre deepchem deepchem[torch] torch_geometric
  2. run the code
  3. error
Traceback (most recent call last):
  File "/Users/syedzayyanmasud/Desktop/prog/sth/main.py", line 21, in <module>
    hello = model.fit(dataset)
  File "/Users/syedzayyanmasud/Desktop/prog/sth/venv/lib/python3.9/site-packages/deepchem/models/torch_models/torch_model.py", line 338, in fit
    return self.fit_generator(
  File "/Users/syedzayyanmasud/Desktop/prog/sth/venv/lib/python3.9/site-packages/deepchem/models/torch_models/torch_model.py", line 422, in fit_generator
    inputs, labels, weights = self._prepare_batch(batch)
  File "/Users/syedzayyanmasud/Desktop/prog/sth/venv/lib/python3.9/site-packages/deepchem/models/torch_models/gcn.py", line 355, in _prepare_batch
    inputs = dgl.batch(dgl_graphs).to(self.device)
  File "/Users/syedzayyanmasud/Desktop/prog/sth/venv/lib/python3.9/site-packages/dgl/heterograph.py", line 5709, in to
    ret._graph = self._graph.copy_to(utils.to_dgl_context(device))
  File "/Users/syedzayyanmasud/Desktop/prog/sth/venv/lib/python3.9/site-packages/dgl/utils/internal.py", line 585, in to_dgl_context
    device_type = nd.DGLContext.STR2MASK[F.device_type(ctx)]
KeyError: 'mps'

Expected behavior

Environment

  • OS: MacOS Monterey
  • Python version: 3.10
  • DeepChem version: 2.7.2
  • RDKit version (optional):
  • TensorFlow version (optional):
  • PyTorch version (optional):
  • Any other relevant information:

Additional context

The hack is not using mps backends, or uninstall dgl and re-install it again from source but that did not work for me but there's a workaround now apparently https://github.com/dmlc/dgl/issues/4344 .

syedzayyan avatar Sep 11 '23 16:09 syedzayyan

Hi @syedzayyan which version of torch are you using? I would recommend you to use Torch from https://developer.apple.com/metal/pytorch/ the newer versions of pytorch resolve the error

shreyasvinaya avatar Dec 14 '23 05:12 shreyasvinaya