pub struct CosineEmbeddingLossBackward {
pub name: &'static str,
pub id: String,
pub block_size: i32,
pub kernel_source: String,
pub entry_point_source: String,
pub source: String,
}Expand description
Cosine embedding loss backward (per-row).
Let c = cos_sim, n1 = ||x1||, n2 = ||x2||, r1 = 1/n1, r2 = 1/n2.
dc/dx1[k] = (x2[k]*r2 - c*x1[k]*r1) * r1
dc/dx2[k] = (x1[k]*r1 - c*x2[k]*r2) * r2
coeff = -dy if y == 1
= dy if y == -1 and cos_sim > margin
= 0 otherwise
dx1 = coeff * dc/dx1, dx2 = coeff * dc/dx2Grid: [n_rows, 1, 1]. BLOCK_SIZE must equal next_power_of_two(n_dim).
Fields§
§name: &'static strThe kernel function’s name (e.g. "flash_attention2_forward").
id: StringUnique kernel identifier: fn_name + dtype(s) + const values joined by “__”.
block_size: i32Compile-time kernel constant, from the annotated fn’s const generics.
kernel_source: StringThe original kernel function source.
entry_point_source: StringThe Rust source of the generated C-ABI entry-point wrapper function.
source: StringCombined source (kernel_source + "\n\n" + entry_point_source); used by the Kernel trait.
Implementations§
Trait Implementations§
Source§impl Kernel for CosineEmbeddingLossBackward
impl Kernel for CosineEmbeddingLossBackward
Source§type Args<'__a> = (*mut f32, *mut f32, *mut f32, *mut f32, *mut f32, *mut f32, i32, i32, f32)
type Args<'__a> = (*mut f32, *mut f32, *mut f32, *mut f32, *mut f32, *mut f32, i32, i32, f32)
This kernel’s launch-argument tuple type.
Source§fn kernel_source(&self) -> &str
fn kernel_source(&self) -> &str
This kernel’s body source, without the entry-point wrapper.
Source§fn entry_point_source(&self) -> &str
fn entry_point_source(&self) -> &str
Returns the Rust source of the generated C-ABI entry-point wrapper function.
Source§fn entry_point_name(&self) -> String
fn entry_point_name(&self) -> String
Returns the PTX symbol name for this kernel:
"{name}_entry_point".Auto Trait Implementations§
impl Freeze for CosineEmbeddingLossBackward
impl RefUnwindSafe for CosineEmbeddingLossBackward
impl Send for CosineEmbeddingLossBackward
impl Sync for CosineEmbeddingLossBackward
impl Unpin for CosineEmbeddingLossBackward
impl UnsafeUnpin for CosineEmbeddingLossBackward
impl UnwindSafe for CosineEmbeddingLossBackward
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more