# 【share\_params】why modules' share\_params method doesn't free allocated memory?

**URL:** <https://discuss.tvm.apache.org/t/share-params-why-modules-share-params-method-doesnt-free-allocated-memory/14271>\
**Category:** Questions\
**Created:** [January 30, 2023, 8:40am UTC](https://discuss.tvm.apache.org/t/share-params-why-modules-share-params-method-doesnt-free-allocated-memory/14271 "2023-01-30T08:40:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chenugray](https://discuss.tvm.apache.org/letter_avatar_proxy/v4/letter/c/3be4f8/32.png) [@chenugray](https://discuss.tvm.apache.org/u/chenugray)\
**Post date:** [January 30, 2023, 8:40am UTC](https://discuss.tvm.apache.org/t/share-params-why-modules-share-params-method-doesnt-free-allocated-memory/14271/1 "2023-01-30T08:40:15Z")

</div>

graph executor setup all device memory in method’s `GraphExecutor::SetupStorage`, the allocated memory are stored in storage\_pool\_.

> <https://github.com/apache/tvm/blob/3c81d9bbaccbd5cc138789a8e1bbd54d338f3134/src/runtime/graph_executor/graph_executor.cc#L469>

In my opinion, share params is for memory-saving accross multi same instance.

 ![image](https://discuss.tvm.apache.org/uploads/default/original/2X/2/2ad95295de83e0918e240d5b409626b52fc00f58.png)

> <https://github.com/apache/tvm/blob/3c81d9bbaccbd5cc138789a8e1bbd54d338f3134/src/runtime/graph_executor/graph_executor.cc#L704>

why not remove from storage\_pool\_? so that the reference of origin `NDArray` use count will decrease to 0, then the allocated duplicated memory will be freed.

@masahi

I use this method try to run multi same instance, but the memory not get decreased.

> <https://github.com/apache/tvm/blob/3c81d9bbaccbd5cc138789a8e1bbd54d338f3134/src/runtime/graph_executor/graph_executor.cc#L333>

---

<div class="post-metadata">

**Author:** ![chenugray](https://discuss.tvm.apache.org/letter_avatar_proxy/v4/letter/c/3be4f8/32.png) [@chenugray](https://discuss.tvm.apache.org/u/chenugray)\
**Post date:** [February 15, 2023, 8:56am UTC](https://discuss.tvm.apache.org/t/share-params-why-modules-share-params-method-doesnt-free-allocated-memory/14271/2 "2023-02-15T08:56:58Z")

</div>

> [@chenugray](#):
>
> ethod try to run multi same instance, but the memory not get decreased.

There migit be some small changes need to update `graph_executor`’s `share_params` method, to free the multi instance’s weight memory that have different batch size or seq\_len. and it works.
