Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/DotLLM.Cuda/CudaKernels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ public void LaunchDequantToF16(nint src, QuantizationType srcDtype,
{
case QuantizationType.F16:
// Already FP16, just copy
CudaDriverApi.cuMemcpyDtoD_v2(dst, src, (nuint)(totalElements * 2)).ThrowOnError();
CudaDriverApi.cuMemcpyDtoD_v2(dst, src, (nuint)((long)totalElements * 2)).ThrowOnError();
return;

case QuantizationType.F32:
Expand Down
2 changes: 1 addition & 1 deletion src/DotLLM.Cuda/CudaTransformerModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public ITensor Forward(ReadOnlySpan<int> tokenIds, ReadOnlySpan<int> positions,
}

// 5. Final RmsNorm (last token only)
nint lastHidden = _state.HiddenState + (nint)((seqLen - 1) * hiddenSize * h);
nint lastHidden = _state.HiddenState + (nint)((long)(seqLen - 1) * hiddenSize * h);
_kernels.LaunchRmsNorm(lastHidden, _weights.OutputNormWeight, _state.NormOutput,
hiddenSize, eps, 1, s);

Expand Down
6 changes: 5 additions & 1 deletion src/DotLLM.Cuda/CudaWeights.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,11 @@ private static nint UploadAndDequant(nint hostPtr, QuantizationType qt,
int outputDim, int inputDim,
List<nint> allocs, CudaKernels kernels, nint stream)
{
int totalElements = outputDim * inputDim;
// `checked` rather than widened: every byte size below already casts to long, so this
// element count is the only narrow product — but it is also passed as `int` to
// LaunchConvertF32ToF16 / LaunchDequantToF16, so a long count could not be honoured
// without changing those signatures. Fail loudly instead of wrapping negative (#429).
int totalElements = checked(outputDim * inputDim);
Comment on lines +245 to +249

if (qt == QuantizationType.F16)
{
Expand Down