Skip to content

Instantly share code, notes, and snippets.

View s3nh's full-sized avatar
🦊

s3nh s3nh

🦊
View GitHub Profile
@vatsalsaglani
vatsalsaglani / mistral_ctx.py
Last active July 2, 2024 13:05
Token counting and message token management for MistralAI
from typing import List, Dict, Literal, Union
from transformers import AutoTokenizer
class MistralAICtx:
def __init__(self, model_name: str):
assert "mistral" in model_name, "MistralCtx only available for Mistral models"
self.tokenizer = AutoTokenizer.from_pretrained(
"mistralai/Mistral-7B-Instruct-v0.2")
@152334H
152334H / dpo_unsloth.py
Last active December 27, 2023 23:24
neuralhermes with unsloth lora. requires base model to be hacked from mistral -> llama
import torch
from unsloth import FastLlamaModel
from transformers import TrainingArguments
from datasets import load_dataset
from trl import DPOTrainer
model_name = "teknium/OpenHermes-2.5-Mistral-7B"
model_name = "./OpenHermes-2.5-Mistral-7B"
new_model = "NeuralHermes-2.5-Mistral-7B"
@veekaybee
veekaybee / normcore-llm.md
Last active July 21, 2024 13:28
Normcore LLM Reads

Anti-hype LLM reading list

Goals: Add links that are reasonable and good explanations of how stuff works. No hype and no vendor content if possible. Practical first-hand accounts of models in prod eagerly sought.

Foundational Concepts

Screenshot 2023-12-18 at 10 40 27 PM

Pre-Transformer Models

@xenova
xenova / tiktoken-to-hf.ipynb
Last active May 10, 2024 00:59
Convert tiktoken tokenizers to the Hugging Face tokenizers format
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Birch-san
Birch-san / flash_attn_processor.py
Created July 21, 2023 17:41
diffusers flash_attn AttnProcessors for qkvpacked self-attn and regular cross-attn
import torch
from typing import Optional
from flash_attn import flash_attn_func, flash_attn_qkvpacked_func
from diffusers.models.attention import Attention
class FlashAttnProcessor:
r"""
Processor for implementing memory efficient attention using flash_attn.
"""
@CoffeeVampir3
CoffeeVampir3 / batched.py
Created July 18, 2023 00:58
batched sdxl
import torch
from pipe import StableDiffusionXLPipelineNoWatermark
from pipei2i import StableDiffusionXLImg2ImgPipelineNoWatermark
from diffusers import DiffusionPipeline
from PIL import Image
import os
import gc
import pandas as pd
import random, sys
import os
import sys
from typing import List
import fire
import torch
import transformers
from datasets import load_dataset, DatasetDict
from transformers import Seq2SeqTrainer, TrainerCallback, TrainingArguments, TrainerState, TrainerControl
from transformers.trainer_utils import PREFIX_CHECKPOINT_DIR
@0xabad1dea
0xabad1dea / copilot-risk-assessment.md
Last active September 11, 2023 10:21
Risk Assessment of GitHub Copilot

Risk Assessment of GitHub Copilot

0xabad1dea, July 2021

this is a rough draft and may be updated with more examples

GitHub was kind enough to grant me swift access to the Copilot test phase despite me @'ing them several hundred times about ICE. I would like to examine it not in terms of productivity, but security. How risky is it to allow an AI to write some or all of your code?

Ultimately, a human being must take responsibility for every line of code that is committed. AI should not be used for "responsibility washing." However, Copilot is a tool, and workers need their tools to be reliable. A carpenter doesn't have to

@dataplayer12
dataplayer12 / CMakeLists.txt
Last active August 10, 2020 12:11
Inference on video using C++ API of retinanet
add_executable(infervideo infervideo.cpp)
target_link_libraries(infervideo PRIVATE retinanet ${OpenCV_LIBS} cuda ${CUDA_LIBRARIES})
@tracek
tracek / librosa_parallel.py
Created February 19, 2019 06:24
Running librosa parallel for loops with multiprocessing and joblib
# The script illustartes stunning difference on my machine with processing of signal with multiprocessing and joblib.
# The slowness of multiprocessing is likely caused by oversubscription
import time
import numpy as np
import librosa
from joblib import Parallel, delayed
from functools import partial
from multiprocessing import Pool