Skip to content

Instantly share code, notes, and snippets.

View thepycoder's full-sized avatar

Victor Sonck thepycoder

View GitHub Profile
@thepycoder
thepycoder / transformers_endpoint.sh
Last active October 12, 2022 11:44
Serving create endpoint transformers
clearml-serving --id <your_service_ID> model add --engine triton \
--endpoint "transformer_model" \
--model-id <your_model_ID> \
--preprocess examples/huggingface/preprocessing.py \
--input-size "[-1]" "[-1]" "[-1]" \
--input-type int32 int32 int32 \
--input-name "input_ids" "token_type_ids" "attention_mask" \
--output-size "[2]" \
--output-type float32 \
--output-name "output" \
@thepycoder
thepycoder / upload_model.sh
Created October 11, 2022 08:57
Register model
clearml-serving --id <your_service_ID> model upload --name "Transformer ONNX" --project "Hugginface Serving" --path triton_models/transformer_tensorrt_model/1/model.bin
@thepycoder
thepycoder / triton_ensemble.sh
Last active October 11, 2022 08:45
Triton Ensemble
# Convert a Huggingface model to ONNX
docker run -it --rm --gpus all \
-v $PWD:/project ghcr.io/els-rd/transformer-deploy:0.5.1 \
bash -c "cd /project && \
convert_model -m \"philschmid/MiniLM-L6-H384-uncased-sst2\" \
--backend tensorrt onnx \
--seq-len 16 128 128"
# This will have outputted a triton_models/ folder,
# which we can now serve using Triton
@thepycoder
thepycoder / fastapi.py
Created October 11, 2022 08:43
FastAPI Server
import torch
from fastapi import FastAPI
from transformers import AutoTokenizer, BatchEncoding, TensorType, AutoModelForSequenceClassification
application = FastAPI()
tokenizer = AutoTokenizer.from_pretrained("philschmid/MiniLM-L6-H384-uncased-sst2")
model = AutoModelForSequenceClassification.from_pretrained("philschmid/MiniLM-L6-H384-uncased-sst2").to('cuda:0')
@thepycoder
thepycoder / remote_execution.py
Created August 16, 2022 11:14
Executing remotely
# ...
# Loggers
data_dict = None
if RANK in {-1, 0}:
loggers = Loggers(save_dir, weights, opt, hyp, LOGGER) # loggers instance
if loggers.clearml:
loggers.clearml.task.execute_remotely(queue='my_queue') # <------ ADD THIS LINE
# Data_dict is either None is user did not choose for ClearML dataset or is filled in by ClearML
data_dict = loggers.clearml.data_dict
# ...
@thepycoder
thepycoder / agent.sh
Created August 16, 2022 11:13
ClearML agent
clearml-agent daemon --queue <queues_to_listen_to> [--docker]
@thepycoder
thepycoder / train_data.sh
Created August 16, 2022 11:13
Training with ClearML Dataset
python train.py --img 640 --batch 16 --epochs 3 --data clearml://<your_dataset_id> --weights yolov5s.pt --cache
@thepycoder
thepycoder / create.sh
Created August 16, 2022 11:12
Create Add Close
# Optionally add --parent <parent_dataset_id> if you want to base
# this version on another dataset version, so no duplicate files are uploaded!
clearml-data create --name coco128 --project YOLOv5
clearml-data add --files .
clearml-data close
@thepycoder
thepycoder / sync.sh
Last active August 16, 2022 11:15
ClearML Data Sync
cd coco128
clearml-data sync --project YOLOv5 --name coco128 --folder .
@thepycoder
thepycoder / dir_tree_highlight
Created August 16, 2022 11:11
Directory tree highlight
..
|_ yolov5
|_ datasets
|_ coco128
|_ images
|_ labels
|_ coco128.yaml # <---- HERE!
|_ LICENSE
|_ README.txt