Why is the "Use in Transformers" button displaying wrong thing?
I am looking at:mosaicml/mpt-1b-redpajama-200b · Hugging FaceIf I click the “Use in Transformers” button it shows:from transformers import MosaicGPT

model = MosaicGPT.from_pretrained("mosaicml/mpt-1b-redpajama-200b")This fails if I copy+paste it becauseMosaicGPTis not part of thetransformerslibrary.If I look at the model card they give this example instead:import transformers
model = transformers.AutoModelForCausalLM.from_pretrained('mosaicml/mpt-1b-redpajama-200b', trust_remote_code=True)This works, i.e.AutoModelForCausalLMknows how to use the custom code in the model repo.If I look at theconfig.jsonfor this model I can see:{
  "architectures": [
    "MosaicGPT"
  ],
  "auto_map": {
    "AutoConfig": "configuration_mosaic_gpt.MosaicGPTConfig",
    "AutoModelForCausalLM": "mosaic_gpt.MosaicGPT"
  },
}So it seems like the “Use in Transformers” button is maybe just taking thearchitecturesvalue and not making use of theauto_map?But then if I look atdistilbert-base-uncased-finetuned-sst-2-english · Hugging FaceI see different again. The “Use in Transformers” button gives:from transformers import AutoTokenizer, AutoModelForSequenceClassification

tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")

model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")…providing both a tokenizer and the model, and both usingAuto*classes.Theconfig.jsonfor the model has only:{
  "architectures": [
    "DistilBertForSequenceClassification"
  ],
}and noauto_map.So there’s something more going on
2023-04-21T08:57:19Z
So… I found these docs:Integrate your library with the HubIt seems like there is no way to configure a correct model sample code for that button just from within your repo config.  Instead you have to make a Pull Request to the HFhub-docsrepo and add it to this central filehub-docs/Libraries.ts at main · huggingface/hub-docs · GitHubSeems a bit clunky (probably why few models have done that) but I guess that makes sense for any models which are unable to make use of theAutoModelFor*machinery.But for ones that do it seems like the “Use in Transformers” button could make more of an effort to display a working code sample automatically.And wouldn’t it be nicer if there was also a standard config entry for providing/overriding this snippet?
2023-04-21T13:51:06Z
This is a bug in the widget, which looks in the architecture, then at some metadata we have for Transforemrs to convert it to an auto class (that’s why you see an auto-class for DistilBert). Opening an issue internally to get this fixed, thanks for flagging!
2023-04-21T14:59:19Z
Related… is there a way to introspect from code which models will need to use thefrom_pretrained(trust_remote_code=True)option when usingAutoModelFrom*?(I mean other than just trying to load it without the flag and get an error and then trying again with it)
2023-04-21T16:21:30Z
You can inspect their config ahead of loading and look for the auto_map key.
2023-04-22T06:47:39Z
So presence of theauto_mapkey means it is a model that uses custom code?
2023-04-24T14:22:13Z
Yes, exactly!