[BUG]: math.prod is not always available
🐛 Describe the bug
Hi, I use py37 while math.prod is New in version 3.8. I suggest replace the math.prod with other func. such as:
from functools import reduce
import operator
317 # return math.prod(self.size_global())
318 return reduce(operator.mul, self.size_global(), 1)
Here is the math.prod I found in the source codes. grep -rn "math.prod" py37/ py37/lib/python3.7/site-packages/torch/distributed/_shard/sharding_spec/chunk_sharding_spec_ops/matrix_ops.py:187: st_size = math.prod(st.size()) # type: ignore[attr-defined] py37/lib/python3.7/site-packages/torch/distributed/_shard/sharding_spec/chunk_sharding_spec_ops/matrix_ops.py:188: shape_size = math.prod(shape) # type: ignore[attr-defined] py37/lib/python3.7/site-packages/torch/distributed/_shard/sharding_spec/chunk_sharding_spec_ops/matrix_ops.py:222: st_size = math.prod(st.size()) # type: ignore[attr-defined] py37/lib/python3.7/site-packages/torch/distributed/_shard/sharding_spec/chunk_sharding_spec_ops/matrix_ops.py:223: shape_size = -1 * math.prod(shape) # type: ignore[attr-defined] py37/lib/python3.7/site-packages/torch/distributed/_shard/sharding_spec/chunk_sharding_spec_ops/matrix_ops.py:381: local_size = math.prod(local_tensor.size()[shape_start:]) # type: ignore[attr-defined] py37/lib/python3.7/site-packages/torch/distributed/_shard/sharding_spec/chunk_sharding_spec_ops/matrix_ops.py:382: st_size = math.prod(st.size()[shape_start:]) # type: ignore[attr-defined] py37/lib/python3.7/site-packages/torch/nn/init.py:293: # math.prod is not always available, accumulate the product manually Binary file py37/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSans.ttf matches py37/lib/python3.7/site-packages/transformers/models/data2vec/configuration_data2vec_audio.py:284: return math.prod(self.conv_stride) py37/lib/python3.7/site-packages/transformers/models/big_bird/modeling_big_bird.py:213: if len(array.shape) > len(pointer.shape) and math.prod(array.shape) == math.prod(pointer.shape): py37/lib/python3.7/site-packages/colossalai/tensor/colo_tensor.py:317: # return math.prod(self.size_global()) py37/lib/python3.7/site-packages/colossalai/zero/init_ctx/init_context.py:117: # math.prod is not always available, accumulate the product manually py37/lib/python3.7/site-packages/colossalai/nn/_ops/view.py:41: #org_prod = math.prod(org_sp) py37/lib/python3.7/site-packages/colossalai/nn/_ops/view.py:42: #tgt_prod = math.prod(tgt_sp)
Environment
No response
Sure. Thanks for raising this issue. I will get to fix this now.