opentensor / bittensor

Internet-scale Neural Networks
https://www.bittensor.com/
MIT License
816 stars 274 forks source link

Why weight value must be int in hashing weights commit? #2047

Open toilaluan opened 2 weeks ago

toilaluan commented 2 weeks ago

Describe the bug

I faced a error when adding commit/reveal weights to subnet Finally i found that weights must be a list of int, though weights should be a float list sum to 1 as before. This function: https://github.com/opentensor/bittensor/blob/master/bittensor/utils/weight_utils.py#L372

To Reproduce

Run Validator on this PR https://github.com/NicheTensor/NicheImage/pull/75

Expected behavior

/home/ubuntu/miniconda3/envs/main/lib/python3.10/site-packages/bittensor/utils/weight_utils.py:3 │ │ 88 in │ │ │ │ 385 │ │ │ 386 │ vec_values = Vec(data=None, sub_type="U16") │ │ 387 │ vec_values.value = [ │ │ ❱ 388 │ │ U16(ScaleBytes(value.to_bytes(2, "little"))) for value in values │ │ 389 │ ] │ │ 390 │ values = ScaleBytes(vec_values.encode().data) AttributeError: 'float' object has no attribute 'to_bytes'

Screenshots

No response

Environment

Linux Ubuntu

Additional context

No response

ibraheem-opentensor commented 2 weeks ago

Hello @toilaluan, Can you use weight_utils.convert_weights_and_uids_for_emit to normalize the weights? This should convert them to int cc: @opendansor

toilaluan commented 2 weeks ago

@ibraheem-opentensor thanks, i gonna try it