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
This pull request modifies the Tensor operators involving primitives to immediately dispose the Scalar object they create, rather than waiting for the garbage collector.
a possible workaround i can think of: carefully call torch.Tensor.add_ (or same kind method) w/ using declared TorchSharp.Scalar typed alpha (or same kind argument) explicitly.
other {modules,functions} that directly use specified .NET typed arguments for forward calculation also have possible same symptom.
a possible workaround i can think of: carefully call torch.Tensor.leaky_relu{,_} (or other same kind method) w/ using declared TorchSharp.Scalar typed negative_slope (or other same kind arguments) explicitly.
TorchSharp torch.arange may internally call another torch.arange w/ implicit TorchSharp.Scalar conversions from hardcoded 0 and/or 1.
IMHO, relying implict conversions to type inherits IDisposable (i mean TorchSharp.Scalar) inside TorchSharp easily produces serious memory leak that won't be able to workaround by user side.
most probably, someone would have to do global screening (and hopefully fixing) for TorchSharp.Scalar (and torch.Tensor as well if possible) w/ temporary disabling their implicit conversions, otherwise TorchSharp definetly can not be used for any applications run long time.
and most of deep learning based applications usually run long time; e.g. long time training, FPS speed inference iteration.
another possible solution i can think of is making TorchSharp.DisposeScope to cover TorchSharp.Scalar as well?
@hiyuh if you want to make a pull request onto my branch with your additions, I'd happily merge it so that they can be part of the review for this pull request.
@ds5678
thanks.
i'm grandually moving my task from "avoiding memory leak in my app code" to "fix leak in TorchSharp".
i'll let you know if my outcome does make something better.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request modifies the
Tensoroperators involving primitives to immediately dispose theScalarobject they create, rather than waiting for the garbage collector.