-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Gluon export changing params #19354
Comments
This problem is compounded by the bug in the lambda function used to allocate new tensors for graph passes: NDArray* arr = new NDArray(shape, ctx, false, dtype); |
It further compounds in Gluon where creating the new Parameter doesnt set the dtype explicitly:
Instead we should be creating the param = Parameter(name, dtype=param_data.dtype) |
@samskalicky thanks for the fix! |
Description
When exporting a model from Gluon, some param values can be modified:
https://github.com/apache/incubator-mxnet/blob/ce1e68260eb3cf9219ae4d59df8bdde7361802ec/python/mxnet/gluon/block.py#L1354
The
_reduce
function here actually performs a sum/division:https://github.com/apache/incubator-mxnet/blob/ce1e68260eb3cf9219ae4d59df8bdde7361802ec/python/mxnet/gluon/parameter.py#L406
If the data type is floating point, then the resulting IEEE FP standard calls for a rounding operation. Even though summing by 1 and dividing by 1 should result in the same value, it may be slightly altered.
If specific binary data is encoded within a param, then this operation will modify that data and cause corruption.
Possible solution
I propose checking the length of the block, and if it is 1 then skipping the sum/divide operation.
The text was updated successfully, but these errors were encountered: