Skip to main content

Upload and download models

tip

Recommended tutorials before starting starting uploading and downloading models.

1. Sign in

Before you start using the CLI, you need to log in with your username and password.

stochasticx login --username "my_email@email.com" --password "my_password"

2. Create and upload models

Download a Hugging Face model and save it in the disk. In this tutorial, bert-large-uncased-whole-word-masking-finetuned-squad model will be downloaded from the Hugging Face Hub. It is a model finetuned on the SQuAD dataset.

from transformers import AutoTokenizer, AutoModelForQuestionAnswering

tokenizer = AutoTokenizer.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad")
tokenizer.save_pretrained("./bert-squad")

model = AutoModelForQuestionAnswering.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad")
model.save_pretrained("./bert-squad")

Now you can upload this model to the Stochastic platform. Use the following command:

stochasticx models upload \
--name "bert-squad" \
--dir_path "./bert-squad" \
--type "hf"
info
  • name: will allow you to identify the model later.
  • dir_path: directory path where your model is located.
  • type: model type. In this case a Hugging Face model

3. List and inspect your models

You can list your models with the following command:

stochasticx models ls
CLI output
[+] Collecting uploaded models

┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━┳━━━━━━━━━━┓
┃ Id ┃ Name ┃ Directory path ┃ Type ┃ Uploaded ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━╇━━━━━━━━━━┩
│ 62e3a5aab5beb3002644093e │ bert-squad │ │ hf │ True │
└──────────────────────────┴─────────────────────────┴────────────────┴──────┴──────────┘

Inspect a model to get more details about it:

stochasticx models inspect --id "62e3a5aab5beb3002644093e"
CLI output
Model ID: 62e3a5aab5beb3002644093e ; Name: bert-squad ; Directory path: None ; Model type: hf ; Uploaded: True


{
"model_type":"bert",
"id2label":"None",
"label2id":"None",
"max_position_embeddings":512,
"torch_dtype":"float32",
"vocab_size":30522,
"hugging_face_tasks":[
"BertForQuestionAnswering"
],
"model_size":1336507185,
"specific_model_info":{
"_name_or_path":"bert-large-uncased-whole-word-masking-finetuned-squad",
"attention_probs_dropout_prob":0.1,
"classifier_dropout":"None",
"hidden_act":"gelu",
"hidden_dropout_prob":0.1,
"hidden_size":1024,
"initializer_range":0.02,
"intermediate_size":4096,
"layer_norm_eps":1e-12,
"num_attention_heads":16,
"num_hidden_layers":24,
"pad_token_id":0,
"position_embedding_type":"absolute",
"transformers_version":"4.18.0",
"type_vocab_size":2,
"use_cache":true
}
}

4. Download a specific model

You can also download these models in your local system:

stochasticx models download \
--id "62e9195598855200266c0497" \
--path "./downloaded_model.zip"
CLI output
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 248.0M/248.0M [00:02<00:00, 6.87MiB/s]
info
  • model_id: model ID you want to download.
  • local_path: local path where you want to save this model. Note that the downloaded model will be a zip file.