はい、承知いたしました。llama-cpp-python の内部構造や開発に関心のある方向けに、開発者ドキュメントを作成します。
llama-cpp-python は、C++ で実装された高性能な LLM 推論ライブラリ llama.cpp の Python バインディングです。主な目的は、llama.cpp の持つ高速な CPU/GPU 推論能力、メモリ効率(特に量子化モデル)、そして豊富な機能を、Python 開発者が容易に利用できるようにすることです。
| 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" |
| from PIL import Image | |
| import hpsv2 | |
| import torch | |
| class HPSv2: | |
| @classmethod | |
| def INPUT_TYPES(s): | |
| return { | |
| "required": { | |
| "images": ("IMAGE", ), |
| ================================================================================================================================================================ | |
| 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] -- |
| 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)) | |
| # 逆シグモイド関数の微分 |
| 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) |
| 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: |
| import random | |
| import comfy.patcher_extension | |
| kawaii_aegigoe_list = [ | |
| "んっ…♡", | |
| "あぁんっ…!", | |
| "はぅっ…♡", | |
| "くぅ…ん…", | |
| "ひゃんっ!", | |
| "ふぁ…♡", |
| import torch | |
| from PIL import Image, ImageDraw, ImageFont | |
| import numpy as np | |
| from comfy.cli_args import args | |
| import os | |
| FONT_PATH = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf" | |
| def flatten_dict(d): | |
| items = {} |