tch-rs icon indicating copy to clipboard operation
tch-rs copied to clipboard

VarStore copy method doesn't return error if it's empty.

Open HyeokSuLee opened this issue 3 years ago • 0 comments

I think this function should also needs to return error when target is empty.

    //make src varstore
    let vs = nn::VarStore::new(device);

    // src variables created
    let _ = model(&vs.root(), test_env.observation_space(), 3);
    println!("src vs after model creation : {:?}", vs);

    // make target varstore
    let mut vs_target = nn::VarStore::new(device);
    
    // copy variables src to target
    let copy_result = vs_target.copy(&vs);
    println!("copy src vs to target vs: {:?}", copy_result);

    /* OUTPUT
src vs after model creation : VarStore { variables_: Mutex { data: Variables { named_variables: {"cl.bias": [0.026885006576776505], "al.weight": Tensor[[3, 1024], Ok(Float)], "l2.bias": Tensor[[256], Ok(Float)], "l3.weight": Tensor[[1024, 256], Ok(Float)], "l3.bias": Tensor[[1024], Ok(Float)], "al.bias": [0.018262110650539398, -0.01045459508895874, -0.011823229491710663], "l2.weight": Tensor[[256, 512], Ok(Float)], "cl.weight": Tensor[[1, 1024], Ok(Float)], "l1.bias": Tensor[[512], Ok(Float)], "l1.weight": Tensor[[512, 252], Ok(Float)]}, trainable_variables: [Var { tensor: Tensor[[512], Ok(Float)], group: 0 }, Var { tensor: Tensor[[512, 252], Ok(Float)], group: 0 }, Var { tensor: Tensor[[256], Ok(Float)], group: 0 }, Var { tensor: Tensor[[256, 512], Ok(Float)], group: 0 }, Var { tensor: Tensor[[1024], Ok(Float)], group: 0 }, Var { tensor: Tensor[[1024, 256], Ok(Float)], group: 0 }, Var { tensor: [0.026885006576776505], group: 0 }, Var { tensor: Tensor[[1, 1024], Ok(Float)], group: 0 }, Var { tensor: [0.018262110650539398, -0.01045459508895874, -0.011823229491710663], group: 0 }, Var { tensor: Tensor[[3, 1024], Ok(Float)], group: 0 }] }, poisoned: false, .. }, device: Cpu }

copy src vs to target vs: Ok(())

target vs: VarStore { variables_: Mutex { data: Variables { named_variables: {}, trainable_variables: [] }, poisoned: false, .. }, device: Cpu }

HyeokSuLee avatar Jul 03 '22 19:07 HyeokSuLee