Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
b387190
feat: module fusion API for kernels
michaelbenayoun Apr 10, 2026
6bc9402
fix: improve __repr__ for fused modules
michaelbenayoun Apr 10, 2026
62d4454
wip: integration to KernelConfig
michaelbenayoun Apr 10, 2026
4082fe1
wip: add temporary example
michaelbenayoun Apr 10, 2026
ac4a699
wip: pattern matching in KernelConfig and actual kernel repo
michaelbenayoun Apr 13, 2026
e13111f
refactor: move relevant code to hub_kernels.py
michaelbenayoun Apr 13, 2026
d9d53f0
docs: reformat docstring
michaelbenayoun Apr 13, 2026
e1c7f3f
refactor: remove comment
michaelbenayoun Apr 13, 2026
db0b7f0
Merge branch 'main' into fused_kernels
michaelbenayoun Apr 13, 2026
e21d06e
Merge branch 'main' into fused_kernels
michaelbenayoun Apr 27, 2026
bd640ae
refactor: update example script for testing
michaelbenayoun Apr 27, 2026
323b000
wip: remove apply_fusions method
michaelbenayoun Apr 27, 2026
fe3002d
wip: add core feature for integration with the current fusing API
michaelbenayoun Apr 27, 2026
b541453
fix: move kernel mapping patching to kernelize
michaelbenayoun Apr 28, 2026
b3d73a7
wip: update example script
michaelbenayoun Apr 28, 2026
0845222
wip: add transform_model method for WeightTransform
michaelbenayoun May 1, 2026
ecfd97d
wip: conversion_mapping in Kernel
michaelbenayoun May 1, 2026
973a616
Merge branch 'main' into extended_kernels_api
michaelbenayoun May 1, 2026
0f0a64b
wip: remove things from __all__
michaelbenayoun May 4, 2026
91177ae
wip: remove imports
michaelbenayoun May 4, 2026
2636c06
fix: remove register_fusion_pattern path
michaelbenayoun May 4, 2026
573d9f0
Merge branch 'main' into extended_kernels_api
michaelbenayoun May 4, 2026
f7c15bd
fix: remove unused attribute
michaelbenayoun May 4, 2026
f9d4299
wip: update experimentation script
michaelbenayoun May 5, 2026
847dbd4
refactor: add convert as abstract method
michaelbenayoun May 5, 2026
4443c9a
style: reformat hub_kernels.py
michaelbenayoun May 5, 2026
51c59c9
wip: transform_model API
michaelbenayoun May 5, 2026
4c58503
wip: transform_model API, WeightTransform
michaelbenayoun May 5, 2026
a7f983f
wip: transform_model API, WeightConverter
michaelbenayoun May 5, 2026
b8d860f
wip: transform_model API, WeightConverter
michaelbenayoun May 5, 2026
3d5f353
wip: make transform_model idempotent
michaelbenayoun May 6, 2026
c35b513
refactor: infer_kernel_fusion_transforms
michaelbenayoun May 6, 2026
6e369c0
style: regexs -> regexes
michaelbenayoun May 6, 2026
731d0b7
refactor: register_kernel_fusions
michaelbenayoun May 6, 2026
4e56ad3
refactor: post transformation cleanup
michaelbenayoun May 6, 2026
96ac123
Merge branch 'main' into extended_kernels_api
michaelbenayoun May 6, 2026
105a403
style: fix comment
michaelbenayoun May 7, 2026
b1c9645
test: add TestApplyTransformsToMetaModel tests
michaelbenayoun May 7, 2026
b10b864
test: add kernels test
michaelbenayoun May 7, 2026
d1bd06d
Merge branch 'main' into extended_kernels_api
michaelbenayoun May 7, 2026
fb0a748
test: fix hub_kernels package reload
michaelbenayoun May 12, 2026
ded8b5f
style: ruff
michaelbenayoun May 12, 2026
6d6411b
Merge branch 'main' into extended_kernels_api
michaelbenayoun May 12, 2026
318553e
refactor: do not create dynamic classes in test
michaelbenayoun May 12, 2026
2a24760
refactor: no dynamic class creation in tests
michaelbenayoun May 12, 2026
8136781
refactor: test
michaelbenayoun May 13, 2026
aa7743a
Merge branch 'main' into extended_kernels_api
michaelbenayoun May 13, 2026
17f4a9e
fix: TYPE_CHECKING imports were broken
michaelbenayoun May 13, 2026
8ec88d1
Merge branch 'main' into extended_kernels_api
michaelbenayoun May 13, 2026
fabadca
wip: get rid of transform_model methods
michaelbenayoun May 19, 2026
e1f3a83
wip: move tests
michaelbenayoun May 19, 2026
68c3659
wip: make conversion happen before fused module instantiation
michaelbenayoun May 19, 2026
041182f
refactor
michaelbenayoun May 19, 2026
519e673
wip: move conversion_mapping inside the init
michaelbenayoun May 19, 2026
88e0aee
wip: without any transform_model
michaelbenayoun May 26, 2026
ad0e24e
wip: remove dead code
michaelbenayoun May 26, 2026
3924cf3
wip: api imrpovement
michaelbenayoun May 26, 2026
c948834
wip: refactor
michaelbenayoun May 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions fused_qwen_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import torch

from transformers import AutoModelForCausalLM, AutoTokenizer, KernelConfig


model_id = "michaelbenayoun/qwen3-tiny-4kv-heads-4layers-random"
tokenizer = AutoTokenizer.from_pretrained(model_id)
inputs = tokenizer("Hello, how are you?", return_tensors="pt")

# --- baseline: plain model, no fusion ---
print("=" * 60)
print("Loading baseline model (no fusion)...")
baseline = AutoModelForCausalLM.from_pretrained(model_id, device_map="cuda")
baseline.eval()
inputs = {k: v.to(baseline.device) for k, v in inputs.items()}

with torch.no_grad():
baseline_out = baseline(**inputs).logits
print("Baseline output shape:", baseline_out.shape)
# del baseline

# --- fused model ---
print("=" * 60)
print("Loading fused model...")

kernel_repo_id = "michaelbenayoun/dummy-rmsnorm-mlp:RMSNormMLP"
#kernel_repo_id = "michaelbenayoun/dummy-rmsnorm-mlp-with-transformations:RMSNormMLP"
kernel_config = KernelConfig(
{
(
("RMSNorm", "model.layers.*.post_attention_layernorm"),
("MLP", "model.layers.*.mlp"),
): kernel_repo_id,
},
)

fused_model = AutoModelForCausalLM.from_pretrained(
model_id, use_kernels=True, kernel_config=kernel_config, device_map="cuda"
)
fused_model.eval()
print(fused_model)

with torch.no_grad():
fused_out = fused_model(**inputs).logits
print("Fused output shape:", fused_out.shape)

# --- compare ---
print("=" * 60)
print("Max diff fused vs baseline:", (fused_out - baseline_out).abs().max().item())
4 changes: 2 additions & 2 deletions src/transformers/core_model_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import os
import re
import traceback
from abc import abstractmethod
from abc import ABC, abstractmethod
from collections import defaultdict
from collections.abc import Callable
from concurrent.futures import Future, ThreadPoolExecutor
Expand Down Expand Up @@ -80,7 +80,7 @@ def build_glob_alternation(
return alternation, src_group_to_glob, tgt_group_to_glob


class ConversionOps:
class ConversionOps(ABC):
"""Base class for weight conversion operations."""

def __repr__(self):
Expand Down
2 changes: 2 additions & 0 deletions src/transformers/integrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
],
"hqq": ["prepare_for_hqq_linear"],
"hub_kernels": [
"FusedModuleBase",
"LayerRepository",
"lazy_load_kernel",
"register_kernel_mapping",
Expand Down Expand Up @@ -221,6 +222,7 @@
from .higgs import HiggsLinear, dequantize_higgs, quantize_with_higgs, replace_with_higgs_linear
from .hqq import prepare_for_hqq_linear
from .hub_kernels import (
FusedModuleBase,
LayerRepository,
lazy_load_kernel,
register_kernel_mapping,
Expand Down
Loading
Loading