Overview
Thepush_to_hf_hub module provides:
- Command-line tool for uploading models
- Python API for programmatic uploads
- Automatic configuration file generation
- Model card creation
- Support for safetensors format
Installation
Ensure you have the required dependencies:Command-Line Usage
Use thepush_to_hf_hub module as a command-line tool:
Required Parameters
--model: Name of the model architecture (e.g.,ViT-B-32,ViT-L-14)--pretrained: Path to checkpoint file or pretrained tag--repo-id: Hugging Face Hub repository ID (format:username/repo-name)
Optional Parameters
--precision: Model precision (fp32,fp16,bf16) - default:fp32--image-mean: Override image mean values for preprocessing--image-std: Override image std values for preprocessing--image-interpolation: Image resize interpolation method (bicubic,bilinear)--image-resize-mode: Image resize mode (shortest,longest,squash)--hf-tokenizer-self: Make tokenizer config point to the uploaded model itself
Examples
Example 1: Upload Trained Model
Upload a model you trained locally:Example 2: Upload with Custom Preprocessing
Upload a model with custom preprocessing parameters:Example 3: Re-upload Existing Model
Re-upload an existing OpenCLIP model to your Hub:Example 4: Upload with Self-Referencing Tokenizer
Upload a model with custom tokenizer that references itself:--hf-tokenizer-self flag makes the tokenizer configuration point to the uploaded model repository instead of the original tokenizer source.
Python API
You can also upload models programmatically:Basic Upload
Upload with Custom Configuration
Upload with Model Card
Manual Upload with Custom Files
What Gets Uploaded
When you push a model to the Hub, the following files are created:Model Weights
open_clip_pytorch_model.bin: PyTorch weights (pickle format)open_clip_model.safetensors: SafeTensors weights (recommended)
Configuration
open_clip_config.json: Model architecture and preprocessing configuration
Tokenizer Files
tokenizer_config.json: Tokenizer configurationvocab.json,merges.txt: Tokenizer vocabulary (for BPE tokenizers)- Other tokenizer-specific files
Model Card
README.md: Automatically generated model card with metadata
Loading Uploaded Models
Once uploaded, anyone can load your model:Model Card Customization
Create comprehensive model cards for better documentation:Best Practices
-
Use Descriptive Repo Names
-
Include Training Information
- Dataset name and size
- Training duration
- Key hyperparameters
- Performance metrics
-
Provide Usage Examples
- Include code snippets in model card
- Show both inference and fine-tuning
- Document any special requirements
-
Use SafeTensors Format
-
Version Your Models
- Use tags or branches for different versions
- Document changes between versions
-
Test Before Uploading
-
Add Relevant Tags
Troubleshooting
Authentication Error
Repository Already Exists
Large File Upload Issues
Missing Configuration
Tokenizer Issues
--hf-tokenizer-self.
