Skip to content

Instantly share code, notes, and snippets.

View aasthavar's full-sized avatar
🎯
Focusing

Aastha Varma aasthavar

🎯
Focusing
View GitHub Profile
@aasthavar
aasthavar / sample.txt
Last active June 4, 2024 08:38
deepmind_code_contests_sample
{
'name': '76_B. Mice',
'description': 'Modern researches has shown that a flock of hungry mice '
'searching for a piece of...',
'public_tests': {'input': ['3 2 0 2\n0 1 3\n2 5\n'], 'output': ['1\n']},
'private_tests': {'input': ['20 18 1 2\n'
'-9999944 -9999861 -9999850 -9999763 -9999656 '
'-9999517 -9999375 -999927...',
...,
'7 11 10 20\n'
@aasthavar
aasthavar / sagemaker-invoke-endpoint.py
Last active September 21, 2023 13:22
AWS Sagemaker Invoke Endpoint
import boto3
import json
client = boto3.client('sagemaker-runtime')
input_text = """[INST] Hi! [/INST]
Hello! How are you?
[INST] I am great, thanks for asking. Could you help me with a task? [/INST]"""
input_data = {
@aasthavar
aasthavar / delete_endpoint_configs.py
Created September 19, 2023 11:38
Delete endpoint configurations
import boto3
from pprint import pprint
client = boto3.client('sagemaker')
def main():
endpoint_config_names = []
for key in paginate(client.list_endpoint_configs):
endpoint_config_names.append(key['EndpointConfigName'])
@aasthavar
aasthavar / delete-sagemaker-endpoints.py
Last active July 21, 2023 13:49
delete-sagemaker-endpoints
import boto3
from pprint import pprint
client = boto3.client('sagemaker')
def main():
endpoint_names = []
for key in paginate(client.list_endpoints):
@aasthavar
aasthavar / delete-sagemaker-models.py
Created July 16, 2023 16:41
Delete all sagemaker models
import boto3
from pprint import pprint
client = boto3.client('sagemaker')
def main():
model_names = []
for key in paginate(client.list_models):
@aasthavar
aasthavar / cuda-fix.py
Created April 19, 2023 14:32
Cuda memory out of error fix
Quick Fixes
(Cuda Memory out error): Depends on the further error text
Option 1:
import gc
import torch
def report_gpu():
print(torch.cuda.list_gpu_processes())
gc.collect()
torch.cuda.empty_cache()
@aasthavar
aasthavar / hf-import.py
Created April 19, 2023 13:02
HuggingFace Libraries Import
# !pip install transformers datasets evaluate accelerate --quiet
import time
import warnings
warnings.filterwarnings("ignore")
from tqdm.auto import tqdm
import collections
import numpy as np
@aasthavar
aasthavar / inference.py
Created April 19, 2023 13:00
Inference Example
newline, bold, unbold = "\n", "\033[1m", "\033[0m"
text1 = "Translate to German: My name is Arthur"
text2 = "A step by step recipe to make bolognese pasta:"
for text in [text1, text2]:
query_response = query_endpoint(text.encode("utf-8"), endpoint_name=endpoint_name)
generated_text = parse_response(query_response)
print(
@aasthavar
aasthavar / logging.py
Last active March 22, 2023 14:53
Python Logger setup
import logging
import sys
# Set up logging
logger = logging.getLogger(__name__)
logging.basicConfig(
level=logging.getLevelName("INFO"),
handlers=[logging.StreamHandler(sys.stdout)],
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
@aasthavar
aasthavar / transformers.py
Created March 21, 2023 03:28
Useful transformers related codestuff
del model
del trainer
torch.cuda.empty_cache()