pub fn multi_margin_loss_backward<T: Triton, const BLOCK_SIZE: i32>(
dy_ptr: T::Pointer<f32>,
input_ptr: T::Pointer<f32>,
targets_ptr: T::Pointer<i32>,
dx_ptr: T::Pointer<f32>,
_n_rows: i32,
n_cols: i32,
margin: f32,
)where
T::I32Tensor: Tensor<i32, 1> + Comparison<i32, BoolTensor = T::BoolTensor>,
T::Pointer<f32>: AddOffsets<i32, 1, T::I32Tensor, Output = T::Tensor<T::Pointer<f32>>> + AddOffsets<i32, 1, T::Tensor<i32>, Output = T::Tensor<T::Pointer<f32>>>,
T::Pointer<i32>: AddOffsets<i32, 1, T::I32Tensor, Output = T::Tensor<T::Pointer<i32>>>,
T::Tensor<i32>: Tensor<i32, 1>,Expand description
Multi-margin loss backward (per-row).
Grid: [n_rows, 1, 1]. BLOCK_SIZE must equal next_power_of_two(n_cols).
Two-step write:
- Store
(dy / n_cols) * active_jfor all j in the row. - Atomic-add correction at target:
-(dy / n_cols) * sum(active_all).