Skip to content

Instantly share code, notes, and snippets.

# /// script
# dependencies = [
# "atproto"
# ]
# ///
from atproto import Client
import getpass
import time
@sayakpaul
sayakpaul / aot_compile_with_int8_quant.py
Last active February 2, 2025 17:54
Shows how to AoT compile the Flux.1 Dev Transformer with int8 quant and perform inference.
import torch
from diffusers import FluxTransformer2DModel
import torch.utils.benchmark as benchmark
from torchao.quantization import quantize_, int8_weight_only
from torchao.utils import unwrap_tensor_subclass
import torch._inductor
torch._inductor.config.mixed_mm_choice = "triton"
@linoytsaban
linoytsaban / flux_with_cfg
Last active December 9, 2024 06:26
Flux with CFG and negative prompts
# download FluxCFGPipline
!wget https://raw.githubusercontent.com/linoytsaban/diffusers/refs/heads/dreambooth-lora-flux-exploration/examples/community/pipeline_flux_with_cfg.py
# load pipeline
import diffusers
import torch
from pipeline_flux_with_cfg import FluxCFGPipeline
pipe = FluxCFGPipeline.from_pretrained("black-forest-labs/FLUX.1-dev",
torch_dtype=torch.bfloat16)
@sayakpaul
sayakpaul / run_flux_with_limited_resources.md
Last active February 23, 2025 07:10
This document enlists resources that show how to run Black Forest Lab's Flux with Diffusers under limited resources.
@pcuenca
pcuenca / openelm-coreml.py
Created April 30, 2024 09:55
Convert OpenELM to Core ML (float32)
import argparse
import numpy as np
import torch
import torch.nn as nn
import coremltools as ct
from transformers import AutoTokenizer, AutoModelForCausalLM
# When using float16, all predicted logits are 0. To be debugged.
compute_precision = ct.precision.FLOAT32
compute_units = ct.ComputeUnit.CPU_ONLY
@Artefact2
Artefact2 / README.md
Last active February 27, 2025 11:06
GGUF quantizations overview
@takanotaiga
takanotaiga / i2t.py
Last active September 26, 2024 16:51
i2t ros2
# Copyright 2023 Taiga Takano
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@eavae
eavae / convert_diffusers_lora_to_sd_webui.py
Created August 23, 2023 07:45
A script help you convert diffusers lora to sd webui format
from pathlib import Path
from diffusers import StableDiffusionXLPipeline
import torch
from safetensors.torch import save_file
# text_encoder.text_model.encoder.layers.0.self_attn.k_proj.lora_linear_layer.down.weight
# lora_te_text_model_encoder_layers_0_self_attn_k_proj.lora_down.weight
# 1. text_encoder -> lora_te, text_encoder_2 -> lora_te2
# 2. map
# 3. .weight -> 2 .alpha -> 1 and replace . -> _
import json
import pickle
import struct
import zipfile
import numpy as np
from sentencepiece import SentencePieceProcessor
def rms_norm(x): return (x / np.sqrt(np.square(x).mean(-1, keepdims=True) + 1e-6))
def softmax(x): return (np.exp(x - np.max(x, axis=-1, keepdims=True))) / np.sum((np.exp(x - np.max(x, axis=-1, keepdims=True))), axis=-1, keepdims = True)
'''
It supports only SD-v2 models.
usage:
python simo2kohya.py --unet <simo's unet weight path> --text <simo's text_encoder weight path> --save_to <save path>
(--text is optional)
This code may no longer be available due to updates from both @kohya-ss and @cloneofsimo.
'''