Skip to content

[Torch] Lora kernels compilation#4100

Open
daniil-lyakhov wants to merge 2 commits into
openvinotoolkit:developfrom
daniil-lyakhov:dl/lora_compile
Open

[Torch] Lora kernels compilation#4100
daniil-lyakhov wants to merge 2 commits into
openvinotoolkit:developfrom
daniil-lyakhov:dl/lora_compile

Conversation

@daniil-lyakhov

@daniil-lyakhov daniil-lyakhov commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Changes

  • asymmetric_quantize_lora and symmetric_quantize_lora are wrapped by the CompilationWrapper
  • ReferenceQuantize is updated to be torch.compile friendly: previous code was making graph brakes in the compiled graph
  • CompilationWrapper is updated to skip compilation for nested compiled functions as it is not supported by the PyTorch

Reason for changes

Example https://github.com/openvinotoolkit/nncf/tree/develop/examples/llm_compression/torch/distillation_qat_with_lora
Before:
image
After:
image

Aprox ~25% speed up
With unlimited cache
(torch._dynamo.config.cache_size_limit = 100
torch._dynamo.config.accumulated_cache_size_limit = 100):
image

HW:
Intel(R) Core(TM) i9-10980XE CPU @ 3.00GHz
3x RTX 3090

Related tickets

Tests

Weight compression - success

Test examples - success

@daniil-lyakhov daniil-lyakhov marked this pull request as ready for review June 19, 2026 08:42
@daniil-lyakhov daniil-lyakhov requested a review from a team as a code owner June 19, 2026 08:42
Copilot AI review requested due to automatic review settings June 19, 2026 08:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves performance of Torch LoRA quantization kernels by enabling torch.compile on the LoRA quantize functions, making ReferenceQuantize more compilation-friendly, and preventing unsupported nested compilation in the shared CompilationWrapper.

Changes:

  • Add a nested-compilation guard to CompilationWrapper to avoid calling torch.compile while already in a compile context.
  • Refactor ReferenceQuantize summation helper into class methods to reduce torch.compile graph breaks.
  • Split LoRA quantize functions into internal implementations and wrap them with CompilationWrapper.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
src/nncf/torch/utils.py Prevents nested torch.compile usage inside CompilationWrapper.
src/nncf/torch/quantization/reference.py Refactors summation logic to be more torch.compile friendly.
src/nncf/torch/quantization/quantize_functions.py Wraps LoRA quantize kernels with CompilationWrapper for speedup.

Comment on lines +54 to +55
def _sum_like(self, tensor_to_sum: GeneralizedTensor, ref_tensor: GeneralizedTensor):
"""Warning: may modify tensor_to_sum"""
Comment on lines +73 to +74
def _sum_like_fp32(self, tensor_to_sum: GeneralizedTensor, ref_tensor: GeneralizedTensor):
"""Warning: may modify tensor_to_sum"""
Comment on lines +507 to +508
_asymmetric_quantize_lora = CompilationWrapper(_asymmetric_quantize_lora)
_symmetric_quantize_lora = CompilationWrapper(_symmetric_quantize_lora)
Comment on lines +306 to +307
return _asymmetric_quantize_lora(
input_,
Comment on lines +364 to +365
return _symmetric_quantize_lora(input_, input_shape, A, B, scale, level_low, level_high, levels, eps)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants