TensorFlow is deprecated. New TensorFlow model uploads are no longer accepted — author new models in PyTorch or scikit-learn. The TensorFlow mandatory variables and TensorFlow file-format examples below are retained only as reference for existing TensorFlow experiments, which remain readable.
Use Pre-trained Weights
Upload weights along with your model in theuser.upload_model() step and set weights=True, the default value is False:
user.fetch_seed_weights("<template>") first, see Upload.
Models build locally (no external hubs)
Your model file must build its architecture from local code. tracebloc does not fetch models, weights, tokenizers, or configs from an external hub (such as HuggingFace) while training — a training pod has no such egress. In practice your model file must not:- call
*.from_pretrained("<hub-id>")for a model, tokenizer, or config, or - call
torch.hub.load(...), or reach the same functions indirectly viagetattr(X, "from_pretrained").
model_id, tokenizer_id or hf_token in your model
file is refused at upload too — see the note under
Additional variables.
To start from a pretrained model, download its weights once, build the same
architecture in your model file, and upload the weights alongside it (see
Use pre-trained weights). For text and other NLP
tasks, also ship a tokenizer.json — pass it with
user.upload_model(..., tokenizer="tokenizer.json") or place it next to your
model file.
The uploaded weights file is loaded into the architecture your model file builds,
matching parameter names and shapes exactly. Build the same architecture you
produced the weights from, or the load will fail.
The model zoo’s object detection seeds are the exception: they carry the backbone
only, so the class head starts fresh from
output_classes.Model Code Formats
Model code can be:- A single Python file containing one or more functions
- A single Python file with no functions
- Multiple Python files (zipped), with the main file code outside of any function
- Multiple Python files (zipped), with the main file code inside a function
In case of multiple files saved as .zip format, the files should be directly inside the .zip file. Subdirectory structure in .zip files is not supported.
Folder models (YOLO)
Ayolo object detection model trains with its own loss.py, so it is uploaded as a .zip of model.py and loss.py. user.upload_model() takes one file, and uploading model.py on its own fails with loss.py file missing in the zip.
The model zoo’s YOLO templates are folders (yolo_v1/, yolo_v5/, yolo_v8/), and each ships with a ready-to-upload .zip next to it. Upload the .zip:
model.py and loss.py directly in a .zip (no folder inside it) and upload that file:
Mandatory Variables
PyTorch mandatory variables
The file must contain these variables:- framework : name of the framework for which this model file is created. For PyTorch its value will be pytorch.
- model_type : the training contract the model follows. Valid values depend on the task:
- object_detection:
torchvision_detectionfor torchvision-style detectors (for example Faster R-CNN, RetinaNet, FCOS, SSD and the zoo’s single-file YOLO templatesyolov8_s.py,yolov9_s.py,yolov10_s.py,yolo11_s.py,yolov12_s.pyandyolox_s.py), oryolofor grid models that ship aloss.py(the zoo’syolo_v1/,yolo_v5/andyolo_v8/folders, uploaded as a .zip, see Folder models (YOLO)).rcnnis a legacy alias oftorchvision_detection. An empty or other value is refused at upload. - keypoint_detection:
directfor coordinate outputs,heatmapfor heatmap outputs, orrcnnfor torchvision keypoint detectors. An empty value trains asrcnnunless the model name contains “heatmap”. - Every other PyTorch task: leave it empty.
- object_detection:
- main_class : name of the main class of the model.
- image_size : name of the variable defining the input size considered for creating model layers.
- category : name of the category for which this model file is created. PyTorch supports every task: image_classification, object_detection, keypoint_detection, semantic_segmentation, text_classification, sentence_pair_classification, token_classification, masked_language_modeling, causal_language_modeling, seq2seq, embeddings, tabular_classification, tabular_regression, time_series_classification, time_series_forecasting, time_to_event_prediction. See Model parameters by task for the variables each task adds.
- batch_size : name of the variable defining the batch size of the images considered for creating model layers.
Sklearn mandatory variables
The file must contain these variables:- framework : name of the framework for which this model file is created. For Sklearn its value will be sklearn.
- model_type : name of the model type for which this model file is created. Its value will be either empty or tree or linear or knn or naive or mlp.
- main_class or main_method : name of the main class or main method of the model. Any one of these is necessary for model.
- image_size : name of the variable defining the input size considered for creating model layers.
- category : name of the category for which this model file is created. Sklearn supports tabular_classification and tabular_regression. For time_to_event_prediction, use the
lifelinesorscikit_survivalframework, or PyTorch. - batch_size : name of the variable defining the batch size of the images considered for creating model layers.
Tensorflow mandatory variables
Deprecated — retained for existing TensorFlow experiments. New uploads must use PyTorch or scikit-learn.
- framework : name of the framework for which this model file is created. For tensorflow its value will be tensorflow.
- model_type : name of the model type for which this model file is created. Its value will be either empty or rcnn or heatmap.
- main_method : name of the main function
- input_shape or image_size : name of the variable defining the input shape of the model
- category : name of the category for which this model file is created. Its value will be either of these : image_classification, object_detection, keypoint_detection, text_classification.
- output_classes : name of the variable defining the output shape of the variables. The value of this variable is equal to the number of classes in the dataset.
Additional variables
Some additional variables are required for specific categories- num_feature_points : number of keypoints (
keypoint_detection) or of input columns (tabular_classification,tabular_regression,time_to_event_prediction) for which this model file is created. This variable is used only for those categories.
Do not declare
model_id, tokenizer_id or hf_token in your model file.
If any of them is set, the SDK refuses the upload with “HuggingFace /
hub-referenced models are no longer supported”. A training pod has no egress to
an external hub, so a hub id could not be fetched anyway (see
Models build locally (no external hubs)).
Build the architecture locally and upload its weights instead. Hugging Face
support is removed.Detailed Information on each format
1. Single python file containing one class for pyTorch
All your model code needs to be contained in a single python file with the following structure:1.1 Import Section
Import all the necessary functionality needed to build your model.1.2 Main Class
This is the main method which should return the model as output.- framework = ‘pytorch’
- main_method = ‘Net’
- image_size = 224
- batch_size = 16
2. Single python file containing one class for sklearn
All your model code needs to be contained in a single python file with the following structure:2.2 Import Section
Import all the necessary functionality you need to build your model.2.3 Main Method
This is the main method which should return the model as output.- framework = ‘sklearn’
- main_method = ‘MyModel’
- image_size = 224
- batch_size = 16
3. Single python file containing one/multiple methods for tensorflow
Formats 3 and 4 (TensorFlow) are deprecated and retained only for existing TensorFlow experiments. New uploads must use the PyTorch or scikit-learn formats above.
3.1 Import Section
Import all the necessary functionality you need to build your model.3.2 Supporting Functions
Any kind of functionality that supports the model architecture. This section is optional. This section can be left out if the model architecture does not require it.3.3 Main Method
This is the main method which should return the model as output.- framework = ‘tensorflow’
- main_method = ‘MyModel’
- input_shape = ‘input_shape’
- output_classes = ‘classes’
4. Single python file having no method for tensorflow
All your model code needs to be in a single python file with the following structure: The model file can be broken down into two sections: The Import section and the main code.4.1 Import Section
Import all the necessary functionalities you need to build your model.4.2 Main Code
This is the model code with all layers.- framework = ‘tensorflow’
- main_method = ”
- input_shape = ‘input_shape’
- output_classes = ‘classes’
5. Multiple python files with main file code not contained in a method
In this format the model architecture is defined using multiple python files. But the main file should use the same format as type 1. In order to upload models with this format, zip all python files with the main method containing the mentioned variables and upload the zip file.The main file should contain the variable values as mentioned in the type 1 format. Other files should not contain these variables.
6. Multiple python file with main file code contained in a method
In this format the model architecture is defined using multiple python files. But the main file should use the same format as type 2. In order to upload models with this format, zip all python files with the main method containing the mentioned variables and upload the zip file.The main file should contain the variable values as mentioned in type 2 format. Other files should not contain these variables.
Next Steps
- Configure training parameters: Hyperparameters
Need Help?
- Email us at [email protected]