Skip to content

Instantly share code, notes, and snippets.

View ddh0's full-sized avatar
🤗

ddh0 ddh0

🤗
  • Texas
  • 22:30 (UTC -05:00)
View GitHub Profile
@ddh0
ddh0 / serve.py
Last active July 20, 2026 19:45
single-file example HTTP MCP tool server in Python 3.12.11 (for use with `llama-ui` or any other MCP-capable inference client)
# serve.py
# Python 3.12.11
import os
import re
import sys
import math
import datetime
from typing import Optional, Literal
@ddh0
ddh0 / diff.patch
Created July 2, 2026 19:05
GGML_OP_LIGHTNING_INDEXER patch diff for llama.cpp#24231 (master: `fdb1db87`, branch: `218d39614`)
diff --git a/ggml/include/ggml.h b/ggml/include/ggml.h
index d6807b6dd..a050211b1 100644
--- a/ggml/include/ggml.h
+++ b/ggml/include/ggml.h
@@ -568,6 +568,7 @@ extern "C" {
GGML_OP_RWKV_WKV7,
GGML_OP_SOLVE_TRI,
GGML_OP_GATED_DELTA_NET,
+ GGML_OP_LIGHTNING_INDEXER,
@ddh0
ddh0 / console.log
Created June 13, 2026 20:37
./build/bin/llama-tensor-debug -lv 4 --device none --no-mmap -b 512 -ub 512 -c 4096 -f ~/datasets/ddh0_imat_calibration_data_v2.txt -m ~/gguf/Gemma-4-31B-StyleTune-Q8_0.gguf
warn: LLAMA_ARG_MMAP environment variable is set, but will be overwritten by command line argument --no-mmap
warn: LLAMA_ARG_BATCH environment variable is set, but will be overwritten by command line argument -b
warn: LLAMA_ARG_UBATCH environment variable is set, but will be overwritten by command line argument -ub
0.00.022.162 W main: parameter override: warmup = false
0.00.022.549 I system_info: n_threads = 8 (n_threads_batch = 8) / 16 | CUDA : ARCHS = 890 | USE_GRAPHS = 1 | PEER_MAX_BATCH_SIZE = 128 | CPU : SSE3 = 1 | SSSE3 = 1 | AVX = 1 | AVX2 = 1 | F16C = 1 | FMA = 1 | BMI2 = 1 | AVX512 = 1 | AVX512_VBMI = 1 | AVX512_VNNI = 1 | AVX512_BF16 = 1 | LLAMAFILE = 1 | OPENMP = 1 | REPACK = 1 |
0.00.022.559 I common_init_result: fitting params to device memory ...
0.00.022.559 I common_init_result: (for bugs during this step try to reproduce them with -fit off, or provide --verbose logs if the bug only occurs with -fit on)
0.00.022.804 I common_params_fit_impl: getting device memory data for initial parameters:
@ddh0
ddh0 / ggml-guide.md
Last active July 24, 2026 17:05
A Brief Guide to GGML

A Brief Guide to GGML

DISCLAIMER: I intend for this guide to be helpful and correct, but I make no guarantees. If you find something is inaccurate or missing, please let me know!

Intro

GGML is a C/C++ tensor library for machine learning. It implements:

  • A set of tensor operations
  • Automatic differentiation
# chat_template_txt.py
# Python 3.12.3
import sys
import argparse
import datetime
from typing import TextIO, Optional, Literal
from transformers import AutoTokenizer
@ddh0
ddh0 / eval-callback.cpp
Last active April 5, 2026 04:15
llama.cpp - capture tensors to .npy format
#include "arg.h"
#include "common.h"
#include "log.h"
#include "llama.h"
#include "ggml.h"
#include <map>
#include <cstdio>
#include <string>
#include <vector>
@ddh0
ddh0 / adaptive-p.cpp
Last active December 27, 2025 16:55
Adaptive-P (refer to: https://github.com/ggml-org/llama.cpp/pull/17927 for canonical implementation)
/// adaptive-p: select tokens near a configurable target probability over time.
///
/// the adaptive-p sampler transforms the token probability distribution to favor tokens
/// that fall near a user-configurable probability target.
///
/// internally, the sampler maintains an exponential moving average of the *ORIGINAL*
/// probabilities of selected tokens at each sampling step. it uses this EMA to compute an
/// adapted target probability at each sampling step, thus maintaining the desired target
/// probability over time.
///
@ddh0
ddh0 / train_tokenizer2.py
Created November 25, 2025 03:09
train a tokenizer given one or more parquet files. includes pre-defined special tokens.
# train_tokenizer2.py
# Python 3.12.3
"""Train a `PreTrainedTokenizerFast` given parquet files and a vocabulary size."""
import sys
import argparse
import tempfile
import shutil
import os
@ddh0
ddh0 / low_level_llama.py
Last active June 4, 2025 23:11
Low-level libllama test script
import os
import sys
import ctypes
import numpy as np
from easy_llama import libllama as lib
# -------------------------------------------------------------------------------------------- #
@ddh0
ddh0 / tensor-type-testing.md
Last active April 3, 2025 20:14
tensor-type-testing