torch.BinaryOpConfig
export interface BinaryOpConfig<Op extends BinaryOpNames> {
/**
* Operation name (must match OpSchemas).
*/
readonly op: Op;
/**
* CPU kernel function. Receives two values and returns the result.
* For float32 dtype.
*/
readonly cpu: (a: number, b: number) => number;
/**
* Optional CPU kernel for int32 dtype.
* If not provided and int32 is in dtypes, uses the float32 kernel.
*/
readonly cpuInt32?: (a: number, b: number) => number;
/**
* WebGPU shader entry point name (e.g., 'add_op', 'mul_op').
*/
readonly shaderEntry: string;
/**
* Dtypes to register. Defaults to ['float32', 'int32'].
*/
readonly dtypes?: readonly BinaryDType[];
/**
* Backward function for autograd.
* If not provided, the operation is not differentiable.
*/
readonly backward?: BinaryBackwardFn;
/**
* Setup context function for backward.
* Defaults to saving both inputs.
*/
readonly setupContext?: (
ctx: GradContext,
inputs: { a: TensorLike; b: TensorLike },
output: TensorLike
) => void;
/**
* What to save for backward pass.
* 'inputs' - saves both input tensors (default)
* 'output' - saves the output tensor
* 'none' - saves nothing
* 'a' - saves only the first input
* 'b' - saves only the second input
*/
readonly saveForBackward?: 'inputs' | 'output' | 'none' | 'a' | 'b';
/**
* Tensor method name to call. Defaults to the op name.
*/
readonly tensorMethod?: string;
}Opextends BinaryOpNames- readonly
op(Op) - – Operation name (must match OpSchemas).
- readonly
cpu((a: number, b: number) => number) - – CPU kernel function. Receives two values and returns the result. For float32 dtype.
- readonly
cpuInt32((a: number, b: number) => number)optional - – Optional CPU kernel for int32 dtype. If not provided and int32 is in dtypes, uses the float32 kernel.
- readonly
shaderEntry(string) - – WebGPU shader entry point name (e.g., 'add_op', 'mul_op').
- readonly
dtypes(readonly BinaryDType[])optional - – Dtypes to register. Defaults to ['float32', 'int32'].
- readonly
backward(BinaryBackwardFn)optional - – Backward function for autograd. If not provided, the operation is not differentiable.
- readonly
setupContext(( ctx: GradContext, inputs: { a: TensorLike; b: TensorLike }, output: TensorLike ) => void)optional - – Setup context function for backward. Defaults to saving both inputs.
- readonly
saveForBackward('inputs' | 'output' | 'none' | 'a' | 'b')optional - – What to save for backward pass. 'inputs' - saves both input tensors (default) 'output' - saves the output tensor 'none' - saves nothing 'a' - saves only the first input 'b' - saves only the second input
- readonly
tensorMethod(string)optional - – Tensor method name to call. Defaults to the op name.
Configuration for registering a binary operation.