| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export interface AttentionOutput { |
| |
| values: number[]; |
| |
| raw: Float32Array; |
| } |
| |
| |
| |
| |
| |
| export declare class MultiHeadAttention { |
| private inner; |
| readonly dim: number; |
| readonly numHeads: number; |
| |
| |
| |
| |
| |
| |
| constructor(dim: number, numHeads: number); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| compute(query: number[] | Float32Array, keys: (number[] | Float32Array)[], values: (number[] | Float32Array)[]): AttentionOutput; |
| |
| |
| |
| computeRaw(query: Float32Array, keys: Float32Array[], values: Float32Array[]): Float32Array; |
| get headDim(): number; |
| } |
| |
| |
| |
| export declare class FlashAttention { |
| private inner; |
| readonly dim: number; |
| readonly blockSize: number; |
| |
| |
| |
| |
| |
| |
| constructor(dim: number, blockSize?: number); |
| |
| |
| |
| compute(query: number[] | Float32Array, keys: (number[] | Float32Array)[], values: (number[] | Float32Array)[]): AttentionOutput; |
| computeRaw(query: Float32Array, keys: Float32Array[], values: Float32Array[]): Float32Array; |
| } |
| |
| |
| |
| export declare class HyperbolicAttention { |
| private inner; |
| readonly dim: number; |
| readonly curvature: number; |
| |
| |
| |
| |
| |
| |
| constructor(dim: number, curvature?: number); |
| |
| |
| |
| compute(query: number[] | Float32Array, keys: (number[] | Float32Array)[], values: (number[] | Float32Array)[]): AttentionOutput; |
| computeRaw(query: Float32Array, keys: Float32Array[], values: Float32Array[]): Float32Array; |
| } |
| |
| |
| |
| export declare class LinearAttention { |
| private inner; |
| readonly dim: number; |
| readonly numFeatures: number; |
| |
| |
| |
| |
| |
| |
| constructor(dim: number, numFeatures: number); |
| |
| |
| |
| compute(query: number[] | Float32Array, keys: (number[] | Float32Array)[], values: (number[] | Float32Array)[]): AttentionOutput; |
| computeRaw(query: Float32Array, keys: Float32Array[], values: Float32Array[]): Float32Array; |
| } |
| |
| |
| |
| export declare class LocalGlobalAttention { |
| private inner; |
| readonly dim: number; |
| readonly localWindow: number; |
| readonly globalTokens: number; |
| |
| |
| |
| |
| |
| |
| |
| constructor(dim: number, localWindow: number, globalTokens: number); |
| |
| |
| |
| compute(query: number[] | Float32Array, keys: (number[] | Float32Array)[], values: (number[] | Float32Array)[]): AttentionOutput; |
| computeRaw(query: Float32Array, keys: Float32Array[], values: Float32Array[]): Float32Array; |
| } |
| |
| |
| |
| export interface MoEConfig { |
| dim: number; |
| numExperts: number; |
| topK: number; |
| expertCapacity?: number; |
| } |
| |
| |
| |
| export declare class MoEAttention { |
| private inner; |
| readonly config: MoEConfig; |
| |
| |
| |
| |
| |
| constructor(config: MoEConfig); |
| |
| |
| |
| static simple(dim: number, numExperts: number, topK: number): MoEAttention; |
| |
| |
| |
| compute(query: number[] | Float32Array, keys: (number[] | Float32Array)[], values: (number[] | Float32Array)[]): AttentionOutput; |
| computeRaw(query: Float32Array, keys: Float32Array[], values: Float32Array[]): Float32Array; |
| } |
| |
| |
| |
| export declare function projectToPoincareBall(vector: number[] | Float32Array, curvature?: number): number[]; |
| |
| |
| |
| export declare function poincareDistance(a: number[] | Float32Array, b: number[] | Float32Array, curvature?: number): number; |
| |
| |
| |
| export declare function mobiusAddition(a: number[] | Float32Array, b: number[] | Float32Array, curvature?: number): number[]; |
| |
| |
| |
| export declare function expMap(base: number[] | Float32Array, tangent: number[] | Float32Array, curvature?: number): number[]; |
| |
| |
| |
| export declare function logMap(base: number[] | Float32Array, point: number[] | Float32Array, curvature?: number): number[]; |
| |
| |
| |
| export declare function isAttentionAvailable(): boolean; |
| |
| |
| |
| export declare function getAttentionVersion(): string | null; |
| |
| |
| |
| |
| export declare class GraphRoPeAttention { |
| private inner; |
| readonly dim: number; |
| readonly numHeads: number; |
| readonly maxSeqLen: number; |
| constructor(dim: number, numHeads?: number, maxSeqLen?: number); |
| compute(query: number[] | Float32Array, keys: (number[] | Float32Array)[], values: (number[] | Float32Array)[], positions?: number[]): AttentionOutput; |
| } |
| |
| |
| |
| |
| export declare class EdgeFeaturedAttention { |
| private inner; |
| readonly dim: number; |
| readonly edgeDim: number; |
| constructor(dim: number, edgeDim?: number); |
| compute(query: number[] | Float32Array, keys: (number[] | Float32Array)[], values: (number[] | Float32Array)[], edgeFeatures?: (number[] | Float32Array)[]): AttentionOutput; |
| } |
| |
| |
| |
| |
| export declare class DualSpaceAttention { |
| private inner; |
| readonly dim: number; |
| readonly curvature: number; |
| readonly alpha: number; |
| constructor(dim: number, curvature?: number, alpha?: number); |
| compute(query: number[] | Float32Array, keys: (number[] | Float32Array)[], values: (number[] | Float32Array)[]): AttentionOutput; |
| } |
| |
| |
| |
| export declare class DotProductAttention { |
| private inner; |
| readonly dim: number; |
| constructor(dim: number); |
| compute(query: number[] | Float32Array, keys: (number[] | Float32Array)[], values: (number[] | Float32Array)[]): AttentionOutput; |
| } |
| |
| |
| |
| export declare function parallelAttentionCompute(queries: (number[] | Float32Array)[], keys: (number[] | Float32Array)[], values: (number[] | Float32Array)[], attentionType?: 'dot' | 'multi-head' | 'flash' | 'hyperbolic' | 'linear'): Promise<number[][]>; |
| |
| |
| |
| export declare function batchAttentionCompute(batches: Array<{ |
| query: number[] | Float32Array; |
| keys: (number[] | Float32Array)[]; |
| values: (number[] | Float32Array)[]; |
| }>, attentionType?: 'dot' | 'multi-head' | 'flash' | 'hyperbolic' | 'linear'): Promise<number[][]>; |
| |
| |
| |
| export declare function computeFlashAttentionAsync(query: number[] | Float32Array, keys: (number[] | Float32Array)[], values: (number[] | Float32Array)[]): Promise<number[]>; |
| |
| |
| |
| export declare function computeHyperbolicAttentionAsync(query: number[] | Float32Array, keys: (number[] | Float32Array)[], values: (number[] | Float32Array)[], curvature?: number): Promise<number[]>; |
| |
| |
| |
| export declare class AdamOptimizer { |
| private inner; |
| constructor(learningRate?: number, beta1?: number, beta2?: number); |
| step(gradients: number[] | Float32Array, params: number[] | Float32Array): number[]; |
| } |
| |
| |
| |
| export declare function infoNceLoss(anchor: number[] | Float32Array, positive: number[] | Float32Array, negatives: (number[] | Float32Array)[], temperature?: number): number; |
| |
| |
| |
| export declare function mineHardNegatives(anchor: number[] | Float32Array, candidates: (number[] | Float32Array)[], topK?: number): number[][]; |
| |
| |
| |
| export declare function benchmarkAttention(dim: number, seqLen: number, iterations?: number): Promise<Record<string, { |
| avgMs: number; |
| minMs: number; |
| maxMs: number; |
| }>>; |
| declare const _default: { |
| DotProductAttention: typeof DotProductAttention; |
| MultiHeadAttention: typeof MultiHeadAttention; |
| FlashAttention: typeof FlashAttention; |
| HyperbolicAttention: typeof HyperbolicAttention; |
| LinearAttention: typeof LinearAttention; |
| LocalGlobalAttention: typeof LocalGlobalAttention; |
| MoEAttention: typeof MoEAttention; |
| GraphRoPeAttention: typeof GraphRoPeAttention; |
| EdgeFeaturedAttention: typeof EdgeFeaturedAttention; |
| DualSpaceAttention: typeof DualSpaceAttention; |
| parallelAttentionCompute: typeof parallelAttentionCompute; |
| batchAttentionCompute: typeof batchAttentionCompute; |
| computeFlashAttentionAsync: typeof computeFlashAttentionAsync; |
| computeHyperbolicAttentionAsync: typeof computeHyperbolicAttentionAsync; |
| AdamOptimizer: typeof AdamOptimizer; |
| infoNceLoss: typeof infoNceLoss; |
| mineHardNegatives: typeof mineHardNegatives; |
| projectToPoincareBall: typeof projectToPoincareBall; |
| poincareDistance: typeof poincareDistance; |
| mobiusAddition: typeof mobiusAddition; |
| expMap: typeof expMap; |
| logMap: typeof logMap; |
| isAttentionAvailable: typeof isAttentionAvailable; |
| getAttentionVersion: typeof getAttentionVersion; |
| benchmarkAttention: typeof benchmarkAttention; |
| }; |
| export default _default; |
| |