monkeypatch.kernelize_fixes

monkeypatch.kernelize_fixes

Repairs for transformers’ kernelization under use_kernels=True.

set_use_kernels(True) calls kernelize(), which swaps each module’s _hidden_kernels entries for hub kernels, but two upstream defects crash it: ~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.set_use_kernels 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.