Skip to content

'Use this Model' code snippets for timm models in Transformers could use improvements #1124

@rwightman

Description

@rwightman

There are a few issues with the code snippets currently show for timm models with Transformers (via the wrapper model)

  1. timm and transformers models don't show any pipeline snippet for image-feature-extraction task models
  2. timm models show the same AutoModel.from_pretrained snippet for both feat extraction and image classification models
  3. 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.

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions