Class TorchNativeAttentionKernel
java.lang.Object
smile.llm.attention.TorchNativeAttentionKernel
- All Implemented Interfaces:
AttentionKernel
LibTorch
scaled_dot_product_attention backend.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbackend()Returns the backend this kernel implements.Runs attention.
-
Constructor Details
-
TorchNativeAttentionKernel
public TorchNativeAttentionKernel()Creates a LibTorch SDPA attention kernel.
-
-
Method Details
-
forward
Description copied from interface:AttentionKernelRuns attention.For
AttentionBackend.TORCH_NATIVE,query/key/valueare contiguous[B,H,S,D]/[B,H,L,D]andmaskis optional.For
AttentionBackend.FLASHINFER,queryis[B,H,S,D](or[B,S,H,D]— see kernel docs);key/valuemay benullwhenAttentionContext.isPaged()(KV read from the pool).- Specified by:
forwardin interfaceAttentionKernel- Parameters:
query- query tensor.key- key tensor, ornullwhen paged.value- value tensor, ornullwhen paged.mask- attention mask, ornull.ctx- scale / causal / paged metadata.- Returns:
- attention output matching query layout expected by the caller
(
[B,H,S,D]for both backends in v1).
-
backend
Description copied from interface:AttentionKernelReturns the backend this kernel implements.- Specified by:
backendin interfaceAttentionKernel- Returns:
- backend this kernel implements.
-