facebookresearch / esm

Evolutionary Scale Modeling (esm): Pretrained language models for proteins
MIT License
3.28k stars 643 forks source link

esmfold_v1() error in pl_upgrades branch for pytorch v2 and cuda v12 #696

Open MaxChu719 opened 4 months ago

MaxChu719 commented 4 months ago
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[2], line 1
----> 1 model = esm.pretrained.esmfold_v1()
      2 model = model.eval().cuda()
      4 # Optionally, uncomment to set a chunk size for axial attention. This can help reduce memory.
      5 # Lower sizes will have lower memory requirements at the cost of increased speed.
      6 # model.set_chunk_size(128)

File ~/miniconda3/envs/esmfold/lib/python3.12/site-packages/esm/pretrained.py:419, in esmfold_v1()
    411 def esmfold_v1():
    412     """
    413     ESMFold v1 model using 3B ESM-2, 48 folding blocks.
    414     ESMFold provides fast high accuracy atomic level structure prediction
   (...)
    417     protein sequence.
    418     """
--> 419     import esm.esmfold.v1.pretrained
    420     return esm.esmfold.v1.pretrained.esmfold_v1()

File ~/miniconda3/envs/esmfold/lib/python3.12/site-packages/esm/esmfold/v1/pretrained.py:5
      1 from pathlib import Path
      3 import torch
----> 5 from esm.esmfold.v1.esmfold import ESMFold
      8 def _load_model(model_name):
      9     if model_name.endswith(".pt"):  # local, treat as filepath

File ~/miniconda3/envs/esmfold/lib/python3.12/site-packages/esm/esmfold/v1/esmfold.py:20
     18 from esm import Alphabet
     19 from esm.esmfold.v1.categorical_mixture import categorical_lddt
---> 20 from esm.esmfold.v1.trunk import FoldingTrunk, FoldingTrunkConfig
     21 from esm.esmfold.v1.misc import (
     22     batch_encode_sequences,
     23     collate_dense_tensors,
     24     output_to_pdb,
     25 )
     28 @dataclass
     29 class ESMFoldConfig:

File ~/miniconda3/envs/esmfold/lib/python3.12/site-packages/esm/esmfold/v1/trunk.py:35
     31     epsilon: float = 1e-8
     32     inf: float = 1e5
---> 35 @dataclass
     36 class FoldingTrunkConfig:
     37     _name: str = "FoldingTrunkConfig"
     38     num_blocks: int = 48

File ~/miniconda3/envs/esmfold/lib/python3.12/dataclasses.py:1275, in dataclass(cls, init, repr, eq, order, unsafe_hash, frozen, match_args, kw_only, slots, weakref_slot)
   1272     return wrap
   1274 # We're called as @dataclass without parens.
-> 1275 return wrap(cls)

File ~/miniconda3/envs/esmfold/lib/python3.12/dataclasses.py:1265, in dataclass.<locals>.wrap(cls)
   1264 def wrap(cls):
-> 1265     return _process_class(cls, init, repr, eq, order, unsafe_hash,
   1266                           frozen, match_args, kw_only, slots,
   1267                           weakref_slot)

File ~/miniconda3/envs/esmfold/lib/python3.12/dataclasses.py:994, in _process_class(cls, init, repr, eq, order, unsafe_hash, frozen, match_args, kw_only, slots, weakref_slot)
    991         kw_only = True
    992     else:
    993         # Otherwise it's a field of some type.
--> 994         cls_fields.append(_get_field(cls, name, type, kw_only))
    996 for f in cls_fields:
    997     fields[f.name] = f

File ~/miniconda3/envs/esmfold/lib/python3.12/dataclasses.py:852, in _get_field(cls, a_name, a_type, default_kw_only)
    848 # For real fields, disallow mutable defaults.  Use unhashable as a proxy
    849 # indicator for mutability.  Read the __hash__ attribute from the class,
    850 # not the instance.
    851 if f._field_type is _FIELD and f.default.__class__.__hash__ is None:
--> 852     raise ValueError(f'mutable default {type(f.default)} for field '
    853                      f'{f.name} is not allowed: use default_factory')
    855 return f

ValueError: mutable default <class 'esm.esmfold.v1.trunk.StructureModuleConfig'> for field structure_module is not allowed: use default_factory
asarigun commented 3 months ago

I debugged the code, and after trying this version, the error no longer occurred:

pip install -q git+https://github.com/asarigun/esm.git