net8.0
Leverage BitsAndBytes 4Bit and 8Bit quantization for TorchSharp
Published
Mar 1, 2025
1y ago
Total Downloads
809
809
Install
dotnet add package LittleLittleCloud.TorchSharp.BitsAndBytes --version 0.0.3
| Product | Versions |
|---|---|
| .NET |
README
TorchSharp.BitsAndBytes
The TorchSharp.BitsAndBytes is a C# binding library for bitsandbytes library from Huggingface. It provides 4Bit and 8Bit quantization for TorchSharp models.
Usage
4Bit Quantization && Dequantization
4Bit quantization is only available for CUDA devices.
var input = torch.rand([dim * 4, dim], dtype: ScalarType.Float32).cuda(); // FP32 tensor, must be on cuda device
string quantizedDType = "fp4"; // Available options: "fp4", "nf4"
int blockSize = 64; // can be [64, 128, 256, 512, 1024]
// Quantize to 4Bit
(var quantizedTensor, var absMax, blockSize, var n) = BitsAndByteUtils.Quantize4Bit(input, quantizedDType, blockSize);
// Dequantize to FP32
var dequantizedTensor = BitsAndByteUtils.Dequantize4Bit(quantiedTensor, absMax, input.dtype, quantizedDType, n, input.shape, blockSize);
Changes from Previous Version
No structural changes between v0.0.2 and v0.0.3.
Adoption Assessment
Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.
Compatibility metadata lists 1 target framework; confirm the exact target used by your application.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.