Cut Cross Entropy provides a highly memory-efficient implementation of the linear-cross-entropy loss function, primarily optimized for large language models and high-throughput inference scenarios. It is part of the vLLM project. The current version is 25.1.1, indicating a rapid development cycle, likely following a date-based or frequent release cadence, designed for NVIDIA GPUs.
pip install cut-cross-entropy torch>=2.0.0Verified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `cut_cross_entropy` to calculate the loss. It explicitly checks for CUDA availability, as the library is fundamentally designed for and requires a CUDA-enabled NVIDIA GPU. The example shows both basic usage and an application with `num_total_tokens`, using `float16` for logits as is common for memory-efficient GPU workloads.
Ensure your environment has a CUDA-enabled GPU and a PyTorch installation compiled with CUDA support (e.g., `pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118`).
Always use `from cut_cross_entropy import ...` for imports.
Consider using `torch.float16` for logits where appropriate to maximize memory efficiency and performance, ensuring your model and hardware support it.
Regularly consult the GitHub repository's README, release notes, or changelog for specific updates and potential API adjustments when upgrading to new versions.