Upload and download models
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.
- Python
- CLI
- Platform
from stochasticx.auth.auth import Stochastic
username = "your_email@email.com"
password = "your_password"
Stochastic().login(username, password)
stochasticx login --username "my_email@email.com" --password "my_password"
You can log in on the Stochastic platform website: https://app.stochastic.ai/login
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:
- Python
- CLI
- Platform
from stochasticx.models.models import Model, ModelType
model_to_upload = Model(
name="bert-squad",
dir_path="bert-squad/",
type=ModelType.HUGGINGFACE
)
print(model_to_upload)
model_to_upload.upload()
print(model_to_upload)
Output
Model ID: None ; Name: bert-squad ; Directory path: bert-squad/ ; Model type: hf ; Uploaded: False
Model ID: 62e3a5aab5beb3002644093e ; Name: bert-squad ; Directory path: bert-squad/ ; Model type: hf ; Uploaded: True
stochasticx models upload \
--name "bert-squad" \
--dir_path "./bert-squad" \
--type "hf"
Go to the menu on the left and click on Models
. Once there, you should see a Add model
button in the top left corner.
Once you have clicked on Add model
a new window will be showed. You have to enter a model name, the model type (select HuggingFace
) and select the folder containing your BERT model that you downloaded from the HuggingFace Hub.
- 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:
- Python
- CLI
- Platform
from stochasticx.models.models import Models
models = Models.get_models()
for model in models:
print(model)
CLI output
Model ID: 62e3a5aab5beb3002644093e ; Name: bert-squad ; Directory path: None ; Model type: hf ; Uploaded: True
stochasticx models ls
CLI output
[+] Collecting uploaded models
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━┳━━━━━━━━━━┓
┃ Id ┃ Name ┃ Directory path ┃ Type ┃ Uploaded ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━╇━━━━━━━━━━┩
│ 62e3a5aab5beb3002644093e │ bert-squad │ │ hf │ True │
└──────────────────────────┴─────────────────────────┴────────────────┴──────┴──────────┘
You have uploaded your first model in the Stochastic Platform. Now you should see your model listed on the models page. Here we can see the model is in status pending, it will become successful once we ensured all the files are correct. Only successfully verified models can be used for running jobs.
Inspect a model to get more details about it:
- Python
- CLI
- Platform
model = Models.get_model("62e3a5aab5beb3002644093e")
model.get_model_info()
CLI output
{
"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
}
}
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
}
}
Click on a model card to get more information about it.
4. Download a specific model
You can also download these models in your local system:
- Python
- CLI
- Platform
model = Models.get_model("62e3a5aab5beb3002644093e")
model.download(local_path="downloaded_model.zip")
CLI output
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 248.0M/248.0M [00:02<00:00, 6.87MiB/s]
stochasticx models download \
--id "62e9195598855200266c0497" \
--path "./downloaded_model.zip"
CLI output
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 248.0M/248.0M [00:02<00:00, 6.87MiB/s]
Click on the download icon of a model.
- 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.