-
Couldn't load subscription status.
- Fork 539
Description
There are a few issues with the code snippets currently show for timm models with Transformers (via the wrapper model)
- timm and transformers models don't show any pipeline snippet for image-feature-extraction task models
- timm models show the same AutoModel.from_pretrained snippet for both feat extraction and image classification models
- timm model snippets do not include the pre-processor creation like Transformers snippets
The 1st issue may be partially addressed by #1120
I don't immediately see a path to fixing 2 & 3. The snippets should be the same as for Transformers, so it's not missing snippet code, it is somehow the identification of the AutoModel / Processors.
For 2/3, if a timm model is tagged with image-classification task I'd expect
# Load model directly
from transformers import AutoImageProcessor, AutoModelForImageClassification
processor = AutoImageProcessor.from_pretrained("timm/vit_base_patch16_224.augreg2_in21k_ft_in1k")
model = AutoModelForImageClassification.from_pretrained("timm/vit_base_patch16_224.augreg2_in21k_ft_in1k")
but we currently get this
# Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("timm/vit_base_patch16_224.augreg2_in21k_ft_in1k")
See e.g.
- https://huggingface.co/timm/vit_base_patch16_224.augreg2_in21k_ft_in1k?library=transformers
vs - https://huggingface.co/facebook/deit-base-patch16-224?library=transformers
Am I correct that the fields of TransformersInfo in ModelData are derived from a combo of metadata in the model repo + possibly config and/or preprocessor config files? The code for the population doesn't appear to be here, but seems the auto_model, processor fields may not be populated for timm models in a manner that results in correct snippets.
export interface TransformersInfo {
/**
* e.g. AutoModelForSequenceClassification
*/
auto_model: string;
/**
* if set in config.json's auto_map
*/
custom_class?: string;
/**
* e.g. text-classification
*/
pipeline_tag?: PipelineType;
/**
* e.g. "AutoTokenizer" | "AutoFeatureExtractor" | "AutoProcessor"
*/
processor?: string;
}