Skip to main content
Retrieves the pretrained configuration dictionary for a specific model architecture and pretrained tag. The configuration includes download URLs, preprocessing parameters, and model-specific settings.

Signature

def get_pretrained_cfg(model: str, tag: str) -> dict:
    ...

Parameters

model
str
required
Model architecture name. Must be a valid model from list_models(). Examples: 'ViT-B-32', 'ViT-L-14', 'RN50'.
tag
str
required
Pretrained weights tag. Must be a valid tag for the specified model. Examples: 'openai', 'laion400m_e32', 'datacomp_xl_s13b_b90k'.Tag names are case-insensitive and hyphens/underscores are normalized (e.g., 'laion-400m-e32' and 'laion400m_e32' are equivalent).

Returns

config
dict
Pretrained configuration dictionary containing:
  • url: Direct download URL for weights (if available)
  • hf_hub: Hugging Face Hub repository path (if available)
  • mean: Image normalization mean values (tuple of 3 floats)
  • std: Image normalization std values (tuple of 3 floats)
  • interpolation: Image interpolation method ('bicubic', 'bilinear', etc.)
  • resize_mode: Resize strategy ('shortest', 'squash', 'longest')
  • quick_gelu: Whether model uses QuickGELU activation (bool, optional)
Returns empty dict {} if model or tag not found.

Example

import open_clip

# Get configuration for OpenAI ViT-B-32
cfg = open_clip.get_pretrained_cfg('ViT-B-32', 'openai')
print(cfg)
# Output:
# {
#     'url': 'https://openaipublic.azureedge.net/clip/models/...',
#     'hf_hub': 'timm/vit_base_patch32_clip_224.openai/',
#     'mean': (0.48145466, 0.4578275, 0.40821073),
#     'std': (0.26862954, 0.26130258, 0.27577711),
#     'interpolation': 'bicubic',
#     'resize_mode': 'shortest',
#     'quick_gelu': True
# }

# Get configuration for LAION ViT-L-14
cfg = open_clip.get_pretrained_cfg('ViT-L-14', 'datacomp_xl_s13b_b90k')
print(f"Download from: {cfg.get('hf_hub', 'N/A')}")
print(f"Interpolation: {cfg['interpolation']}")
print(f"Mean: {cfg['mean']}")
print(f"Std: {cfg['std']}")

# Check if config exists
cfg = open_clip.get_pretrained_cfg('ViT-B-32', 'nonexistent_tag')
if not cfg:
    print("Configuration not found")

# Tag normalization (these are equivalent)
cfg1 = open_clip.get_pretrained_cfg('ViT-B-32', 'laion400m-e32')
cfg2 = open_clip.get_pretrained_cfg('ViT-B-32', 'laion400m_e32')
cfg3 = open_clip.get_pretrained_cfg('ViT-B-32', 'LAION400M-E32')
assert cfg1 == cfg2 == cfg3

# Use config to understand preprocessing requirements
cfg = open_clip.get_pretrained_cfg('ViT-B-16-SigLIP', 'webli')
print(f"SigLIP uses mean: {cfg['mean']}")  # (0.5, 0.5, 0.5)
print(f"SigLIP uses std: {cfg['std']}")    # (0.5, 0.5, 0.5)
print(f"SigLIP resize mode: {cfg['resize_mode']}")  # 'squash'

Configuration Fields

Download Sources

  • url: Direct HTTP(S) URL to download weights
  • hf_hub: Hugging Face Hub path in format org/repo/filename or org/repo/

Preprocessing Parameters

  • mean: RGB channel means for normalization. Common values:
    • OpenAI/CLIP: (0.48145466, 0.4578275, 0.40821073)
    • SigLIP: (0.5, 0.5, 0.5)
    • ImageNet: (0.485, 0.456, 0.406)
  • std: RGB channel standard deviations. Common values:
    • OpenAI/CLIP: (0.26862954, 0.26130258, 0.27577711)
    • SigLIP: (0.5, 0.5, 0.5)
    • ImageNet: (0.229, 0.224, 0.225)
  • interpolation: Resizing interpolation method
    • 'bicubic': Higher quality (default for most models)
    • 'bilinear': Faster
    • 'nearest': Fastest, lowest quality
  • resize_mode: How to handle aspect ratios
    • 'shortest': Resize shortest edge, center crop (CLIP default)
    • 'squash': Resize to exact size, may distort (SigLIP default)
    • 'longest': Resize longest edge, center crop

Model-Specific

  • quick_gelu: If True, model uses QuickGELU activation instead of standard GELU

Helper Functions

# Check if a config exists
exists = open_clip.is_pretrained_cfg('ViT-B-32', 'openai')
print(f"Config exists: {exists}")

# Get available tags for a model
tags = open_clip.list_pretrained_tags_by_model('ViT-B-32')
print(f"Available tags: {tags}")

# Get URL only
url = open_clip.get_pretrained_url('ViT-B-32', 'openai')
print(f"Download URL: {url}")

See Also

Build docs developers (and LLMs) love