You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
torch.deleters performance issue on .NET framework cpu target #1435
I discovered this performance issue while using the MNIST dataset.
This only happens with the combination of .NET framework and cpu target. It does not happen with .NET target or cuda.
This is a minimal reproducible source.
// match to MNIST dataset size
var size = 70000;
var tensors = new List<torch.Tensor>(size);
var dev = new torch.Device("cpu");
for (int i = 0; i < size; ++i)
{
tensors.Add(torch.tensor(new[] { 1.0f }, device: dev));
}
Console.WriteLine(tensors.Count);
foreach (var tensor in tensors)
{
tensor.Dispose();
}
tensors.Clear();
Console.WriteLine(tensors.Count);
The profiler indicates ConcurrentDictionary.TryAdd() and ConcurrentDictionary.TryRemove(), but it looks like MulticastDelegate.Equals() is the problem.
For .NET framework and cuda combination, it seems like removed directly on _tensor_generic.
Thank you for reporting the performance issue with torch.deleters on the .NET Framework CPU target. We appreciate your detailed description and the reproducible example you provided. It seems like a complex issue, especially since it doesn't occur with the .NET target or CUDA.
I noticed that this issue has been open for quite some time, and TorchSharp has evolved significantly since then. Could you let us know if this issue is still relevant or if it has been resolved in more recent versions? If it persists, any updated information or benchmarks would be incredibly helpful for us to investigate further.
Thanks again for your contribution to the community!
Activity
hglee commentedon Jan 13, 2025
Maybe related to dotnet/coreclr#11019
And it seems not ported to .NET framework runtime.
hglee commentedon Jan 27, 2025
Hi, it's Jetbrains dotTrace (https://www.jetbrains.com/profiler/).
The upper was measured in timeline mode and the bottom CUDA was measured in tracing mode.
alinpahontu2912 commentedon Feb 16, 2026
Hi @hglee,
Thank you for reporting the performance issue with
torch.deleterson the .NET Framework CPU target. We appreciate your detailed description and the reproducible example you provided. It seems like a complex issue, especially since it doesn't occur with the .NET target or CUDA.I noticed that this issue has been open for quite some time, and TorchSharp has evolved significantly since then. Could you let us know if this issue is still relevant or if it has been resolved in more recent versions? If it persists, any updated information or benchmarks would be incredibly helpful for us to investigate further.
Thanks again for your contribution to the community!
alinpahontu2912 commentedon Feb 17, 2026
Hey @hglee we would also encourage you to switch from .net fx to .net core to benefit from the latest improvements
hglee commentedon Feb 17, 2026
Sorry for late. I tried it again with 0.106.0, but issue still there.
But I agreed to close this issue as not planned, if you have no plan to solve this issue by techincal problem.
FYI, this is a performance in v0.106.0
And comparison between v0.105.2 and v0.106.0, nearly same within error range.