Skip to content

Conversation

@vinx13
Copy link
Member

@vinx13 vinx13 commented May 12, 2022

When NDArray is being stored as ObjectRef, the serializer won't trigger the right path for storage. Under the new serialization mode, we need to be able to leverage the repr_bytes mechanism to save NDArray.

This change is backward compatible -- ndarray saved in previous format will continue to work. And fixes the problem of serialization when NDArray is involved as part of ObjectRef. In the future, we can consider consolidate the NDArray save into the repr_bytes and remove the specialization as we evolve to newer versions

cc @tqchen @areusch

@github-actions github-actions bot requested review from areusch and tqchen May 12, 2022 23:20
data = tvm.nd.array(np.random.rand(*shape).astype(dtype), device=dev)
body = tvm.tir.Evaluate(0)
stmt = tvm.tir.AllocateConst(buf.data, dtype, shape, data, body)
stmt2 = tvm.ir.load_json(tvm.ir.save_json(stmt))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you double-check that you're actually exporting an NDArray into JSON here? i think this might fix it , but it would be great if we could prove it through e.g. non-empty b64ndarray key

Copy link
Member

@tqchen tqchen May 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My read is that it does not go through b64ndarray mechanism, but instead goes through repr_bytes mechanism as @vinx13 commented. The old b64ndarray mechanism should still continue to work. At some time pt perhaps we can move to repr_bytes mechanism for all cases while keeping b64ndarray for one cycle.

The structural equality in the next line should proves the serialization correctness

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a check of alloc_const.data against ref data

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @vinx13! did we ever figure out which mechanism is used to serialize the ndarray though?

Copy link
Member Author

@vinx13 vinx13 May 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will enter this path https://github.com/apache/tvm/blob/main/src/node/serialization.cc#L156 and call the registered set_repr_bytes during indexing, so it won't be saved into b64array section. The node is later saved in https://github.com/apache/tvm/blob/main/src/node/serialization.cc#L276

@junrushao junrushao merged commit e7f1224 into apache:main May 13, 2022
@MichaelJKlaiber
Copy link
Contributor

MichaelJKlaiber commented May 16, 2022

Nice, @vinx13 @junrushao1994 . Amazing. Thanks for the quick fix!

mehrdadh pushed a commit to mehrdadh/tvm that referenced this pull request May 16, 2022
When `NDArray` is being stored as `ObjectRef`, the serializer won't trigger the right path for storage. Under the new serialization mode, we need to be able to leverage the `repr_bytes` mechanism to save `NDArray`.

This change is backward compatible -- ndarray saved in previous format will continue to work. And fixes the problem of serialization when `NDArray` is involved as part of `ObjectRef`. In the future, we can consider consolidate the `NDArray` save into the `repr_bytes` and remove the specialization as we evolve to newer versions
shtinsa pushed a commit to Deelvin/tvm that referenced this pull request May 17, 2022
When `NDArray` is being stored as `ObjectRef`, the serializer won't trigger the right path for storage. Under the new serialization mode, we need to be able to leverage the `repr_bytes` mechanism to save `NDArray`.

This change is backward compatible -- ndarray saved in previous format will continue to work. And fixes the problem of serialization when `NDArray` is involved as part of `ObjectRef`. In the future, we can consider consolidate the `NDArray` save into the `repr_bytes` and remove the specialization as we evolve to newer versions
shingjan pushed a commit to shingjan/tvm that referenced this pull request May 17, 2022
When `NDArray` is being stored as `ObjectRef`, the serializer won't trigger the right path for storage. Under the new serialization mode, we need to be able to leverage the `repr_bytes` mechanism to save `NDArray`.

This change is backward compatible -- ndarray saved in previous format will continue to work. And fixes the problem of serialization when `NDArray` is involved as part of `ObjectRef`. In the future, we can consider consolidate the `NDArray` save into the `repr_bytes` and remove the specialization as we evolve to newer versions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants