# How to set parameter into pipeline module

**URL:** <https://discuss.tvm.apache.org/t/how-to-set-parameter-into-pipeline-module/11375>\
**Category:** Questions\
**Created:** [November 2, 2021, 4:44am UTC](https://discuss.tvm.apache.org/t/how-to-set-parameter-into-pipeline-module/11375 "2021-11-02T04:44:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![popojames](https://discuss.tvm.apache.org/letter_avatar_proxy/v4/letter/p/9dc877/32.png) [@popojames](https://discuss.tvm.apache.org/u/popojames)\
**Post date:** [November 2, 2021, 4:44am UTC](https://discuss.tvm.apache.org/t/how-to-set-parameter-into-pipeline-module/11375/1 "2021-11-02T04:44:40Z")

</div>

Hello @hijiang,

I have followed your work and made some extensions to support such splitting as I mentioned in the previous discussions [Setting the CPU affinity and number of cores locally without RPC Remote - #4 by popojames](https://discuss.tvm.apache.org/t/setting-the-cpu-affinity-and-number-of-cores-locally-without-rpc-remote/11306/4). [Can TVM split work into different layers, and assign layers into different cores? - #10 by hjiang](https://discuss.tvm.apache.org/t/can-tvm-split-work-into-different-layers-and-assign-layers-into-different-cores/11161/10). I was able to split the network and with my own CPU affinity setting.

Now I try to assign **param** of the pre-trained model into the pipeline module, I noticed the function of PipelineModule.set\_input support such setting:

> <https://github.com/apache/tvm/blob/fba531e55f032367acc28090605c5533b2e88f55/python/tvm/contrib/pipeline_executor.py#L222>

However, this function will induce the following error:

`AttributeError: 'Module' object has no attribute 'set_input'`

This is because of the type of **self.graph\_modules\_[mod\_idx]** is something like **Module(GraphExecutor, 27517208)** instead of **tvm.contrib.graph\_executor.GraphModule**. In this case, the latter can access set\_input but the former cannot.

Is there any other way to assign parameters or can I transfer from Module(GraphExecutor, XXX) to tvm.contrib.graph\_executor.GraphModule in this case to set the parameters?

Thanks for your help in advance and many thanks for developing this TVM function.

---

<div class="post-metadata">

**Author:** ![hjiang](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/hjiang/32/1632_2.png) [@hjiang](https://discuss.tvm.apache.org/u/hjiang)\
**Post date:** [November 2, 2021, 7:00pm UTC](https://discuss.tvm.apache.org/t/how-to-set-parameter-into-pipeline-module/11375/2 "2021-11-02T19:00:03Z")

</div>

@popojames , thanks for trying the pipeline runtime, the set params issue will get address in our new patch, you also can try following change as a quick fix.

```auto
diff --git a/python/tvm/contrib/pipeline_executor.py b/python/tvm/contrib/pipeline_executor.py
index bd8c9a768..c1f7842b3 100644
--- a/python/tvm/contrib/pipeline_executor.py
+++ b/python/tvm/contrib/pipeline_executor.py
@@ -157,7 +157,7 @@ def create(pipeline_mods, mod_config):
         mod = graph_executor.GraphModule(
             pipeline_mod["default"](pipeline_mods[pipeline_mod]["dev"])
         )
- mods.append(mod.module)
+ mods.append(mod)

     submodule = PipelineModule(mods, json.dumps(mod_config))
     # submodule = PipelineModule(pipeline_mods, json.dumps(mod_config))
@@ -181,7 +181,7 @@ class PipelineModule(object):
     def __init__ (self, modules, pipeline_config):
         mods = []
         for module in modules:
- mods.append(module)
+ mods.append(module.module)

         pipelinecreate = tvm._ffi.get_global_func("tvm.pipeline_executor.create")
         assert pipelinecreate

```

---

<div class="post-metadata">

**Author:** ![popojames](https://discuss.tvm.apache.org/letter_avatar_proxy/v4/letter/p/9dc877/32.png) [@popojames](https://discuss.tvm.apache.org/u/popojames)\
**Post date:** [November 2, 2021, 9:28pm UTC](https://discuss.tvm.apache.org/t/how-to-set-parameter-into-pipeline-module/11375/3 "2021-11-02T21:28:11Z")

</div>

Thanks for replying, I will try and keep an eye on the new patches. 🙂

---

<div class="post-metadata">

**Author:** ![popojames](https://discuss.tvm.apache.org/letter_avatar_proxy/v4/letter/p/9dc877/32.png) [@popojames](https://discuss.tvm.apache.org/u/popojames)\
**Post date:** [November 3, 2021, 4:05am UTC](https://discuss.tvm.apache.org/t/how-to-set-parameter-into-pipeline-module/11375/4 "2021-11-03T04:05:31Z")

</div>

Hello @hjiang,

Thanks for answering, I was able to feed the params into the model by adopting your change.

But I add one more change: I changed to the following code

> ```
> if params:
> for param in params:
> self.graph_modules_[mod_idx].set_input(**params)
> 
> ```

into the following code to avoid the error

> ```
> if params:
> self.graph_modules_[mod_idx].set_input(**params)
> 
> ```

> <https://github.com/apache/tvm/blob/1ee5831b61b5a196eb99a44a998087f3c9c8c4a1/python/tvm/contrib/pipeline_executor.py#L220>

====================================================================

More info: What I want to do is very similar to do what you have done in [tvm/test\_pipeline\_executor.py at fba531e55f032367acc28090605c5533b2e88f55 · apache/tvm (github.com)](https://github.com/apache/tvm/blob/fba531e55f032367acc28090605c5533b2e88f55/tests/python/relay/test_pipeline_executor.py) To be more specific, I tried to compare the correctness of the pipeline setting, in another word, if I feed the input to with pipeline and run the inference, I was expected to get the same result as I get in without the pipeline setting. Now I was able to achieve so.

Thanks again 🙂
