Skip to content

Instantly share code, notes, and snippets.

View philschmid's full-sized avatar

Philipp Schmid philschmid

View GitHub Profile
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();
# automatic pipeline
pipe=Pipeline('summarization',model="bart")
pipe()
# preprocess(input)
# model(input)
# postprocess(input)
#-------------------------------------------------------------------------#
@philschmid
philschmid / deploy_hub.py
Last active April 16, 2021 06:59
Hugging Face SageMaker Inference
from sagemaker.huggingface import HuggingFaceModel
# Hub Model configuration. https://huggingface.co/models
hub = {
'MODEL_ID':'distilbert-base-uncased-distilled-squad',
'TASK':'question-answering'
}
# create Hugging Face Model Class
huggingface_model = HuggingFaceModel(
{
"context": "Saisonbedingt ging der Umsatz im ersten Quartal des Geschäftsjahres 2019 um 4 Prozent auf 1.970 Millionen Euro zurück, verglichen mit 1.047 Millionen Euro im vierten Quartal des vorangegangenen Geschäftsjahres. Leicht rückläufig war der Umsatz in den Segmenten Automotive (ATV) und Industrial Power Control (IPC). Im Vergleich zum Konzerndurchschnitt war der Rückgang im Segment Power Management & Multimarket (PMM) etwas ausgeprägter und im Segment Digital Security Solutions (DSS) deutlich ausgeprägter. Die Bruttomarge blieb von Quartal zu Quartal weitgehend stabil und fiel von 39,8 Prozent auf 39,5 Prozent. Darin enthalten sind akquisitionsbedingte Abschreibungen sowie sonstige Aufwendungen in Höhe von insgesamt 16 Millionen Euro, die hauptsächlich im Zusammenhang mit der internationalen Rectifier-Akquisition stehen. Die bereinigte Bruttomarge blieb ebenfalls nahezu unverändert und lag im ersten Quartal bei 40,4 Prozent, verglichen mit 40,6 Prozent im letzten Quartal des Geschäftsjahres 2018. Da