# AttributeError: 'float' object has no attribute 'copy'

**URL:** <https://discuss.pytorch.org/t/attributeerror-float-object-has-no-attribute-copy/126900>\
**Category:** Uncategorized\
**Created:** [July 16, 2021, 2:30am UTC](https://discuss.pytorch.org/t/attributeerror-float-object-has-no-attribute-copy/126900 "2021-07-16T02:30:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielmanu93](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/d/a88e4f/32.png) [@danielmanu93](https://discuss.pytorch.org/u/danielmanu93)\
**Post date:** [July 16, 2021, 2:30am UTC](https://discuss.pytorch.org/t/attributeerror-float-object-has-no-attribute-copy/126900/1 "2021-07-16T02:30:37Z")

</div>

Hi everyone, I copied the weights of my trained model using “model.state\_dict()” and then I want to update these weights using model.load\_state\_dict(weights) but I’m getting an error "AttributeError: ‘float’ object has no attribute ‘copy’ " as shown in the images below. Any ideas as to how can I can fix this?  
 ![1](https://discuss.pytorch.org/uploads/default/original/3X/5/9/5919ab1848cbe4a42d3103b197e9ac9d1fd21c1b.jpeg)  
 ![2](https://discuss.pytorch.org/uploads/default/original/3X/5/e/5ed83b32d8458f1b14f217c9526680b5108c0d42.jpeg)

 ![3](https://discuss.pytorch.org/uploads/default/original/3X/5/1/51d196512dddf51acebc2d4f9aaf9574814e183c.jpeg)

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [July 16, 2021, 7:46am UTC](https://discuss.pytorch.org/t/attributeerror-float-object-has-no-attribute-copy/126900/2 "2021-07-16T07:46:56Z")

</div>

Could you post the model definition of `x_global_model`, as it seems the `state_dict()` operation returns a `float`, while an `OrderedDict` would be expected?

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [July 16, 2021, 11:44pm UTC](https://discuss.pytorch.org/t/attributeerror-float-object-has-no-attribute-copy/126900/4 "2021-07-16T23:44:35Z")

</div>

It seems you are manually appending some “weights” to `g_global_weights` and try to treat it as a `state_dict`, which is causing the issue.  
You would have to use the workflow posted previously, i.e. create the `state_dict` via:

```python
sd = model.state_dict()

```

and load it via:

```python
model.load_state_dict(sd)

```

afterwards.  
Currently you are replacing the initial `state_dict` with an empty `list` and append the (unknown) values.

PS: you can post code snippets by wrapping them into three backticks ```, which would make debugging easier.
