Giter Club home page Giter Club logo

Comments (5)

LysandreJik avatar LysandreJik commented on September 12, 2024

cc @Rocketknight1 :)

from transformers.

Rocketknight1 avatar Rocketknight1 commented on September 12, 2024

Hi @ljw20180420, I'm not sure that a custom pipeline with a custom model in a totally different repo is supported. In particular, doing things this way makes it very hard to know what the model kwarg to pipeline() is supposed to mean - is it the repo you're loading the pipeline from or the repo you're loading the model from?

I think a better approach would be:

  1. Make sure the repos you're interested in, like ljw20180420/SX_spcas9_inDelphi are loadable with the relevant AutoModel classes
  2. Add the pipeline code to each repo
  3. Check if you can load them with pipe = pipeline(model="ljw20180420/SX_spcas9_inDelphi", trust_remote_code=True)

If that workflow creates problems, please let us know here!

from transformers.

ljw20180420 avatar ljw20180420 commented on September 12, 2024

Thank you @Rocketknight1. I now push the pipeline to the same repository as the model at "ljw20180420/SX_spcas9_inDelphi".

from transformers import pipeline
from transformers import AutoModel

inDelphi_model = AutoModel.from_pretrained("ljw20180420/SX_spcas9_inDelphi", trust_remote_code=True)
pipe = pipeline(model="ljw20180420/SX_spcas9_inDelphi", trust_remote_code=True)

AutoModel can load the model. But pipeline cannot be loaded.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ljw/new_fold/old_desktop/CRISPR_AI/.conda/lib/python3.11/site-packages/transformers/pipelines/__init__.py", line 833, in pipeline
    targeted_task, task_options = clean_custom_task(custom_tasks[task])
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ljw/new_fold/old_desktop/CRISPR_AI/.conda/lib/python3.11/site-packages/transformers/pipelines/__init__.py", line 544, in clean_custom_task
    task_info["pt"] = tuple(getattr(transformers, c) for c in pt_class_names)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ljw/new_fold/old_desktop/CRISPR_AI/.conda/lib/python3.11/site-packages/transformers/pipelines/__init__.py", line 544, in <genexpr>
    task_info["pt"] = tuple(getattr(transformers, c) for c in pt_class_names)
                            ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ljw/new_fold/old_desktop/CRISPR_AI/.conda/lib/python3.11/site-packages/transformers/utils/import_utils.py", line 1596, in __getattr__
    raise AttributeError(f"module {self.__name__} has no attribute {name}")
AttributeError: module transformers has no attribute inDelphiModel

from transformers.

Rocketknight1 avatar Rocketknight1 commented on September 12, 2024

Hi @ljw20180420, okay! I took a quick look - I think one issue is that in config.json, you probably want to replace "inDelphiModel" in the pipeline impl key with "AutoModel". The reason is that most pipelines are intended to work with multiple models, and so an AutoModel category is expected here, rather than a single specific model.

If that config.json was generated automatically by transformers, let me know - that might be something we need to fix!

from transformers.

ljw20180420 avatar ljw20180420 commented on September 12, 2024

Thank you @Rocketknight1. I generate config.json by Trainer.push_to_hub() and Pipeline.push_to_hub().
My source codes are at [email protected]:ljw20180420/CRISPR_AI.git. In the folder CRISPR_AI, execute

inDelphi/report_bug.py

The source of report_bug.py is

from inDelphi.configuration_inDelphi import inDelphiConfig
from inDelphi.modeling_inDelphi import inDelphiModel
from inDelphi.pipeline_inDelphi import inDelphiPipeline
from transformers import Trainer
from transformers.pipelines import PIPELINE_REGISTRY
from transformers import pipeline

inDelphiConfig.register_for_auto_class()
inDelphiModel.register_for_auto_class()
inDelphi_model = inDelphiModel(inDelphiConfig())

trainer = Trainer(model = inDelphi_model)
trainer.push_to_hub()

from huggingface_hub import HfApi
api = HfApi()
while True:
    try:
        api.upload_file(
            path_or_fileobj = "inDelphi/inDelphi_inertion_model.pkl",
            path_in_repo = "inDelphi_inertion_model.pkl",
            repo_id = "ljw20180420/tmp_trainer",
            repo_type = "model"
        )
        break
    except:
        print("upload failed, retry")

PIPELINE_REGISTRY.register_pipeline(
    task="predict CRISPR indel",
    pipeline_class=inDelphiPipeline,
    pt_model=inDelphiModel
)
pipe = pipeline(
    task="predict CRISPR indel",
    model="ljw20180420/tmp_trainer",
    trust_remote_code=True
)

pipe.push_to_hub("tmp_trainer")

After trainer.push_to_hub(), I upload an auxiliary file "inDelphi_inertion_model.pkl" (this should be irrelevant). The config.json is

{
  "DELLEN_LIMIT": 60,
  "architectures": [
    "inDelphiModel"
  ],
  "auto_map": {
    "AutoConfig": "configuration_inDelphi.inDelphiConfig",
    "AutoModel": "modeling_inDelphi.inDelphiModel"
  },
  "mid_dim": 16,
  "model_type": "inDelphi",
  "seed": 63036,
  "torch_dtype": "float32",
  "transformers_version": "4.44.2"
}

After register the pipeline, pipe can load the remote model correctly because config.json have no attribute "custom_pipelines". Nevertheless, after pipe.push_to_hub("tmp_trainer"), it will modify config.json to

{
  "DELLEN_LIMIT": 60,
  "_name_or_path": "ljw20180420/tmp_trainer",
  "architectures": [
    "inDelphiModel"
  ],
  "auto_map": {
    "AutoConfig": "configuration_inDelphi.inDelphiConfig",
    "AutoModel": "modeling_inDelphi.inDelphiModel"
  },
  "custom_pipelines": {
    "predict CRISPR indel": {
      "impl": "pipeline_inDelphi.inDelphiPipeline",
      "pt": [
        "inDelphiModel"
      ],
      "tf": []
    }
  },
  "mid_dim": 16,
  "model_type": "inDelphi",
  "seed": 63036,
  "torch_dtype": "float32",
  "transformers_version": "4.44.2"
}

The new attribute causes the bug.

from transformers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.