johannespischinger / senti_anal

MIT License
2 stars 0 forks source link

deploy this model from GS storage #63

Closed michaelfeil closed 2 years ago

michaelfeil commented 2 years ago

Trained a distilbert model

@max-27 thats how the output files under ./cache look like. https://console.cloud.google.com/storage/browser/model_senti_anal/pretrained-distilbert-2022-01-18-13-50-17/

from google.cloud import storage
import pickle

BUCKET_NAME = ...
MODEL_FILE = ...
Localpath = ./model_checkpoint.chpt

client = storage.Client()
bucket = client.get_bucket(BUCKET_NAME)
blob = bucket.get_blob(MODEL_FILE)
blob.download_to_filename(Localpath)

# load one of these options
# 1
model2 = model.load_from_checkpoint(Localpath)

# 2
model_def: pl.LightningModule = hydra.utils.instantiate(
        cfg.model,
        **{
            "model_name_or_path": cfg.data.datamodule.model_name_or_path,
            "train_batch_size": cfg.data.datamodule.batch_size.train,
        },
        optim=cfg.optim,
        data=cfg.data,
        logging=cfg.logging,
        _recursive_=False,
    )

model2 = model.load_from_checkpoint(Localpath)

also requirements.txt / config hydra etc is uploaded.

michaelfeil commented 2 years ago

maybe good idea to get #65 done locally first

michaelfeil commented 2 years ago

is done with functions by max