Skip to content

Module.to doesn't transfer parameters in ParameterList or ParameterDict #1179

@shaltielshmid

Description

@shaltielshmid

When moving a ParameterList or ParameterDict Module, the registered values get moved but the field doesn't get the updated values.

For example, in the case below, the output would be Float32. If you would inspect the _internal_params list you would see that the parameter there is actually Float16.

This also means that the garbage collector will never dispose of the old parameter since they are both being referenced.

Example code:

private class TestModule1 : Module {
    public TestModule1() : base("TestModule1") {
        list.append(Parameter(torch.rand(10)));
    }
    public ParameterList list = new ParameterList();
}
private static void Test() {
    var m = new TestModule1(torch.randn(2, 2), true);
    m.to(ScalarType.Float16);
    
    Console.WriteLine(m.list[0].dtype);
}

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