This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from diffusers import DiffusionPipeline, StableDiffusionXLImg2ImgPipeline | |
import torch | |
model = "stabilityai/stable-diffusion-xl-base-1.0" | |
pipe = DiffusionPipeline.from_pretrained( | |
model, | |
torch_dtype=torch.float16, | |
) | |
pipe.to("cuda") | |
pipe.load_lora_weights("model/", weight_name="pytorch_lora_weights.safetensors") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import gradio as gr | |
from text_generation import Client | |
PROMPT = """<s>[INST] <<SYS>> | |
You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. | |
If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
from datasets import load_dataset | |
from peft import LoraConfig, get_peft_model, prepare_model_for_int8_training | |
from transformers import AutoModelForCausalLM, AutoTokenizer, TrainingArguments | |
from trl import SFTTrainer | |
def train(): | |
train_dataset = load_dataset("tatsu-lab/alpaca", split="train") | |
tokenizer = AutoTokenizer.from_pretrained("Salesforce/xgen-7b-8k-base", trust_remote_code=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
from pdfminer.high_level import extract_text | |
from sentence_transformers import SentenceTransformer, CrossEncoder, util | |
from text_generation import Client | |
PREPROMPT = "Below are a series of dialogues between various people and an AI assistant. The AI tries to be helpful, polite, honest, sophisticated, emotionally aware, and humble-but-knowledgeable. The assistant is happy to help with almost anything, and will do its best to understand exactly what is needed. It also tries to avoid giving false or misleading information, and it caveats when it isn't entirely sure about the right answer. That said, the assistant is practical and really does its best, and doesn't let caution get too much in the way of being useful.\n" | |
PROMPT = """"Use the following pieces of context to answer the question at the end. | |
If you don't know the answer, just say that you don't know, don't try to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import requests | |
import json | |
SLACK_WEBHOOK= os.environ.get("SLACK_WEBHOOK") | |
def send_message(messages, channel="abhishek", username="beast"): | |
""" | |
:param messages: list of texts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test_transform=transforms.Compose([ | |
transforms.Resize(IMAGE_SIZE), | |
transforms.CenterCrop(IMAGE_SIZE), | |
transforms.ToTensor(), | |
transforms.Normalize(IMG_MEAN,IMG_STD) | |
]) | |
test_dataset = CollectionsDatasetTest(csv_file='../input/sample_submission.csv', | |
root_dir='../input/test/', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch.optim as optim | |
from torch.optim import lr_scheduler | |
plist = [ | |
{'params': model_ft.layer4.parameters(), 'lr': 1e-5}, | |
{'params': model_ft.last_linear.parameters(), 'lr': 5e-3} | |
] | |
optimizer_ft = optim.Adam(plist, lr=0.001) | |
lr_sch = lr_scheduler.StepLR(optimizer_ft, step_size=10, gamma=0.1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
from torchvision import transforms | |
# define some re-usable stuff | |
IMAGE_SIZE = 224 | |
NUM_CLASSES = 1103 | |
BATCH_SIZE = 32 | |
device = torch.device("cuda:0") | |
IMG_MEAN = model_ft.mean | |
IMG_STD = model_ft.std |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def train_model(model, | |
data_loader, | |
dataset_size, | |
optimizer, | |
scheduler, | |
num_epochs): | |
criterion = nn.BCEWithLogitsLoss() | |
for epoch in range(num_epochs): | |
print('Epoch {}/{}'.format(epoch, num_epochs - 1)) | |
print('-' * 10) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch.nn as nn | |
import pretrainedmodels as pm | |
model = pm.__dict__["resnet50"](pretrained='imagenet') | |
model.avg_pool = nn.AdaptiveAvgPool2d(1) | |
model.last_linear = nn.Sequential( | |
nn.BatchNorm1d(2048), | |
nn.Dropout(p=0.25), | |
nn.Linear(in_features=2048, out_features=2048), |
NewerOlder