monkeypatch.kernelize_fixes

monkeypatch.kernelize_fixes

Repairs for transformers’ model.kernelize() under use_kernels=True.

kernelize() swaps each module’s _hidden_kernels entries for hub kernels, but two upstream defects crash it (transformers 5.10): ~30 architectures (gemma4, qwen3.5, glm4, olmo, …) stash a bare function it refuses to register, and gpt-oss’s rotary Func keeps a deprecated position_ids parameter that fails the kernels library’s signature check against kernels-community/rotary.

Wraps PreTrainedModel.kernelize to repair the stashes right before the swap: bare functions are dropped (the model’s forward still calls them directly) and position_ids is removed from rotary signature metadata (call behavior unchanged). Both repairs no-op once fixed upstream.