Getting started guide

#1
by youngj8 - opened

Hi, I'm excited by the work you've done on the Pillar0 models and would love to see how it handles some additional datasets. I've been trying to download the model locally and load it using the transforms library but keep running into path errors. Do you have an example of how the model is supposed to be set up and used?

For reference, the Python code is

  from transformers import AutoModel, AutoConfig
  import os
  
  # Load the model from remote
  model_name = "YalaLab/Pillar0-AbdomenCT"
  rev = "d73d111bb278b3f6411f3c8e72c7e6f8a5fb1bb8"
  print("Trying a fresh download")
  config = AutoConfig.from_pretrained(model_name, trust_remote_code=True, revision=rev)
  model = AutoModel.from_config(config, trust_remote_code=True)
 
 # Save the model locally
 local_model_path = "./pillar0_abdomenCt_model/"
 model.save_pretrained(local_model_path)
 
# Check: load the local model
local_model = AutoModel.from_pretrained(
        local_model_path, trust_remote_code=True,
        local_files_only=True, revision=rev)
print("Done.")

where local_model = AutoModel.from_pretrained(... triggers the error

FileNotFoundError: [Errno 2] No such file or directory: '/.../huggingface_cache/modules/transformers_modules/pillar0_abdomenCt_model/a340fb6efc9656f5/multimodal_atlas.py'

When I check, multimodal_atlas.py is indeed missing from the specified directory. Alternatively, I've tried cloning the repository via git clone. All of the files are downloaded, but the directory structure doesn't match what AutoModel.from_pretrained(...) is looking for.

Any help you can provide would be greatly appreciated.

Yala Lab org

Hello, this is a very hacky solution for now--could you try re-running the code? The cache should be populated correctly after the first time it's run. We'll work on a better alternative! Let us know if it works.

Thanks for your response and sorry for the delay on my end. I've finally been able to pick up this implementation again and reran the code I shared in my previous post. Now I'm getting a different error:

/home/username/.condaenvs/dataorg/lib/python3.14/site-packages/timm/models/layers/__init__.py:49: FutureWarning: Importing from timm.models.layers is deprecated, please import via timm.layers
  warnings.warn(f"Importing from {__name__} is deprecated, please import via timm.layers", FutureWarning)
Writing model shards: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 1/1 [00:01<00:00,  1.70s/it]
Loading weights: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 744/744 [00:00<00:00, 1288.92it/s]
Traceback (most recent call last):
  File "/home/username/segmentation-pipelines/pillar_abdominal/test.py", line 16, in <module>
    local_model = AutoModel.from_pretrained(
            local_model_path, trust_remote_code=True,
            local_files_only=True, revision=rev)
  File "/home/username/.condaenvs/dataorg/lib/python3.14/site-packages/transformers/models/auto/auto_factory.py", line 390, in from_pretrained
    return model_class.from_pretrained(
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        pretrained_model_name_or_path, *model_args, config=config, **hub_kwargs, **kwargs
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/username/.condaenvs/dataorg/lib/python3.14/site-packages/transformers/modeling_utils.py", line 4246, in from_pretrained
    loading_info = cls._finalize_model_loading(model, load_config, loading_info)
  File "/home/username/.condaenvs/dataorg/lib/python3.14/site-packages/transformers/modeling_utils.py", line 4402, in _finalize_model_loading
    model._move_missing_keys_from_meta_to_device(
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        loading_info.missing_and_mismatched(),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<2 lines>...
        load_config.hf_quantizer,
        ^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/username/.condaenvs/dataorg/lib/python3.14/site-packages/transformers/modeling_utils.py", line 4665, in _move_missing_keys_from_meta_to_device
    for key in missing_keys - self.all_tied_weights_keys.keys():
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/username/.condaenvs/dataorg/lib/python3.14/site-packages/torch/nn/modules/module.py", line 1967, in __getattr__
    raise AttributeError(
        f"'{type(self).__name__}' object has no attribute '{name}'"
    )
AttributeError: 'CLIPMultimodalAtlas' object has no attribute 'all_tied_weights_keys'. Did you mean: '_tied_weights_keys'?

So it's still an error when loading the model, but it's different now.

Sign up or log in to comment