Skip to content

Attaching unowned tensor to a DisposeScope makes Statistics.DetachedFromScopeCount go negative. #1387

Closed
@mvphelps

Description

@mvphelps

Repro:

[Fact]
    public void DetachedFromScopeCountNegative()
    {
        var stats = DisposeScopeManager.Statistics;
        stats.Reset();
        var t = torch.tensor(1);
        Assert.Equal(0, stats.DetachedFromScopeCount);
        var scope = torch.NewDisposeScope();
        scope.Attach(t);
        Assert.Equal(0, stats.DetachedFromScopeCount);
    }

Removing the branch in DisposeScope.Attach(IEnumerable<IDisposable> disposables) that subtracts fixes the issue and all tests pass, minus any tests checking counts (waiting on PR #1386 prior to fixing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions