Skip to content

Instantly share code, notes, and snippets.

View laksjdjf's full-sized avatar
🌏
On Earth

laksjdjf

🌏
On Earth
View GitHub Profile
import torch
def new_vec(mode, chunks, x):
xs = x.clone().chunk(chunks, dim=0)
ref_xs = torch.cat([xi[0].unsqueeze(0).expand(xi.shape[0], -1, -1).clone() for xi in xs], dim=0).clone()
if mode == "concat":
new_x = x.clone()
return torch.cat([new_x, ref_xs], dim=1)
else:

はい、承知いたしました。llama-cpp-python の内部構造や開発に関心のある方向けに、開発者ドキュメントを作成します。


llama-cpp-python 開発者向けドキュメント

1. 概要 (Overview)

llama-cpp-python は、C++ で実装された高性能な LLM 推論ライブラリ llama.cpp の Python バインディングです。主な目的は、llama.cpp の持つ高速な CPU/GPU 推論能力、メモリ効率(特に量子化モデル)、そして豊富な機能を、Python 開発者が容易に利用できるようにすることです。

import gradio as gr
import pandas as pd
import random
query_general_cache = None
query_character_cache = None
df = pd.read_csv("https://huggingface.co/datasets/furusu/aesthetic_score_danbooru2024/resolve/main/part/aes6_5.csv")
#df = pd.read_csv("aes6_5.csv")
df[["tags", "characters"]] = df[["tags", "characters"]].astype(str)
We can't make this file beautiful and searchable because it's too large.
1girl,5534972
highres,4664611
solo,4604237
long_hair,3972398
breasts,3142271
commentary_request,3080500
looking_at_viewer,2988390
blush,2705742
smile,2598137
import numpy as np
import matplotlib.pyplot as plt
def sigmoid(x):
return 1 / (1 + np.exp(-x))
def inverse_sigmoid(y):
return np.log(y / (1 - y))
# 逆シグモイド関数の微分
================================================================================================================================================================
Layer (type (var_name)) Input Shape Output Shape Param # Kernel Shape
================================================================================================================================================================
SD3Transformer2DModel (SD3Transformer2DModel) -- [1, 16, 128, 128] -- --
├─PatchEmbed (pos_embed) [1, 16, 128, 128] [1, 4096, 1536] -- --
│ └─Conv2d (proj) [1, 16, 128, 128] [1, 1536, 64, 64] 99,840 [2, 2]
├─CombinedTimestepTextProjEmbeddings (time_text_embed) [1] [1, 1536] --
from PIL import Image
import hpsv2
import torch
class HPSv2:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"images": ("IMAGE", ),
import torch
from einops import rearrange, repeat
def block_to_key(block):
if block[0] == "input":
return "in" + str(block[1])
elif block[0] == "output":
return "out" + str(block[1])
elif block[0] == "middle":
return "mid"
@laksjdjf
laksjdjf / chat.py
Last active April 25, 2024 15:20
デフォルト設定はcommand -r 用
import gradio as gr
import json
import requests
import argparse
from dataclasses import dataclass
############### utils ###############
BAN_TOKENS = ["<|END_OF_TURN_TOKEN|>"] # command -r 用の回避トークン
parser = argparse.ArgumentParser()
from comfy.samplers import KSAMPLER
import torch
from comfy.k_diffusion.sampling import default_noise_sampler, to_d
from tqdm.auto import trange
@torch.no_grad()
def sampler_tcd(model, x, sigmas, extra_args=None, callback=None, disable=None, noise_sampler=None, gamma=None):
extra_args = {} if extra_args is None else extra_args
noise_sampler = default_noise_sampler(x) if noise_sampler is None else noise_sampler
s_in = x.new_ones([x.shape[0]])