rusty-gradients 0.2.0

A full-stack deep learning framework in Rust for training and deploying Transformer models. Features multi-backend support (CPU/CUDA/Metal/WASM), 62x GPU acceleration, Safetensors serialization, and BPE tokenization.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// src/losses/cross_entropy.rs
use crate::tensor::Tensor;

/// Вычисляет Cross-Entropy Loss, вызывая стабильную и графо-безопасную операцию
/// `sparse_cross_entropy_op` из `Tensor`.
///
/// # Аргументы
///
/// * `logits` - сырые выходы модели.
/// * `targets` - тензор с правильными индексами.
///
/// # Возвращает
///
/// Скалярный тензор со значением ошибки.
pub fn cross_entropy_loss(logits: &Tensor, targets: &Tensor) -> Tensor {
    logits.sparse_cross_entropy(targets)
}