Skip to content

Instantly share code, notes, and snippets.

View philschmid's full-sized avatar

Philipp Schmid philschmid

View GitHub Profile
from sagemaker.huggingface.model import HuggingFaceModel
from sagemaker.serverless import ServerlessInferenceConfig
from sagemaker.serializers import DataSerializer
import sagemaker
import boto3
try:
role = sagemaker.get_execution_role()
except ValueError:
iam = boto3.client('iam')
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: xgboost-trainer-
annotations: {pipelines.kubeflow.org/kfp_sdk_version: 1.8.12, pipelines.kubeflow.org/pipeline_compilation_time: '2022-04-19T13:58:21.551241',
pipelines.kubeflow.org/pipeline_spec: '{"description": "A trainer that does end-to-end
distributed training for XGBoost models.", "inputs": [{"default": "gs://{{kfp-default-bucket}}",
"name": "output", "optional": true}, {"default": "{{kfp-project-id}}", "name":
"project", "optional": true}, {"default": "HALT_ON_ERROR", "name": "diagnostic_mode",
"optional": true}, {"default": "5", "name": "rounds", "optional": true}], "name":
from sagemaker.huggingface import HuggingFaceModel
from sagemaker.serializers import DataSerializer
import sagemaker
role = sagemaker.get_execution_role()
# Hub Model configuration. https://huggingface.co/models
hub = {
'HF_MODEL_ID':'facebook/wav2vec2-base-960h',
'HF_TASK':'automatic-speech-recognition'
import time
import boto3
import os
import json
from locust import User, task, between
# How to use
# 1. install locust & boto3
# pip install locust boto3
# 2. run benchmark via cli
#!/usr/bin/env python3
from aws_cdk import core as cdk
import os
from pathlib import Path
import shutil
import subprocess
from aws_cdk import (
aws_iam as iam,
aws_sagemaker as sagemaker,
from sagemaker.huggingface import HuggingFaceModel
import sagemaker
role = sagemaker.get_execution_role()
hub = { 'HF_MODEL_ID':'bigscience/T0_3B','HF_TASK':'text2text-generation'}
# create Hugging Face Model Class
huggingface_model = HuggingFaceModel(
transformers_version='4.6.1',
pytorch_version='1.7.1',
py_version='py36',
import torch
import os
from transformers import Wav2Vec2Processor, HubertForCTC
from transformers.pipelines.automatic_speech_recognition import ffmpeg_read
def get_file_size(file_path):
size = os.path.getsize(file_path)
return f"{round(size / 1000 / 1000,2)} MB"
@philschmid
philschmid / archive.py
Created June 23, 2021 12:34
Archive model for Amazon SageMaker
import tarfile
import os
root = "./endpoint"
def main():
cwd = os.getcwd()
os.chdir(root)
files = [os.path.join(path, name) for path, _, files in os.walk(".") for name in files]
@philschmid
philschmid / ingest_squad_dataset.py
Last active June 2, 2021 11:47
Semantic Search: showing how to ingest SQAuD dataset into elastic with infinity + an example on how to query an index
from argparse import ArgumentParser
from asyncio import get_event_loop, gather
from multiprocessing import Process
from requests import post, Session
from re import compile
from datasets import load_dataset
from elasticsearch import Elasticsearch
const API_URL = "https:/{URL}/api/{TASK}"
async function query(payload) {
const body = JSON.stringify(payload)
try {
const response = await fetch(API_URL, {
method: 'post',
body
})
return response.json();