You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by "CharlieFRuan (via GitHub)" <gi...@apache.org> on 2023/12/27 15:30:25 UTC

[PR] [Unity][nnModule] Dynamic shape support in nn Module [tvm]

CharlieFRuan opened a new pull request, #16284:
URL: https://github.com/apache/tvm/pull/16284

   This PR allows dynamic shape in some modules of `nn.Module` (Linear and Embedding), motivated by dynamic vocab size as discussed in https://github.com/mlc-ai/mlc-llm/pull/1417. 
   
   **UX-wise**
   We allow `nn.Parameter("vocab_size", 4096)`, equivalent to `nn.Parameter(tir.Var("vocab_size", "int64"), 4096)`.
   
   **Symbolic relationship across Parameters**
   Besides, we make sure the same symbolic shape for different parameters do not appear twice within the same method. For instance, the following **_would not happen_**:
   ```python
   @R.function
   def prefill(...):
     vocab_size = T.int64()   # for `embed_tokens`
     vocab_size1 = T.int64()  # for `lm_head`
   ```
   
   This is prevented by `str2var_params` in `Exporter`, so that all `embed_tokens.shape[0]` and `lm_head.shape[0]` share the same `tir.Var`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Unity][nnModule] Dynamic shape support in nn Module [tvm]

Posted by "CharlieFRuan (via GitHub)" <gi...@apache.org>.
CharlieFRuan commented on code in PR #16284:
URL: https://github.com/apache/tvm/pull/16284#discussion_r1446136199


##########
python/tvm/relax/frontend/nn/core.py:
##########
@@ -67,6 +67,8 @@
 
 
 _DEFAULT_DTYPE = "float32"
+# If a shape is specified as a string `name`, we create a `tvm.tir.Var(name, "int64")`
+ShapeVar = Union[int, str, tir.PrimExpr]

Review Comment:
   That makes sense, just fixed; thank you!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Unity][nnModule] Dynamic shape support in nn Module [tvm]

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on code in PR #16284:
URL: https://github.com/apache/tvm/pull/16284#discussion_r1445269907


##########
python/tvm/relax/frontend/nn/core.py:
##########
@@ -67,6 +67,8 @@
 
 
 _DEFAULT_DTYPE = "float32"
+# If a shape is specified as a string `name`, we create a `tvm.tir.Var(name, "int64")`
+ShapeVar = Union[int, str, tir.PrimExpr]

Review Comment:
   I see, given this list do not grow, i still think being explicit would be better, since it also helps the readers to learn about what can be passed in directly through signature



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Unity][nnModule] Dynamic shape support in nn Module [tvm]

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on code in PR #16284:
URL: https://github.com/apache/tvm/pull/16284#discussion_r1444728378


##########
python/tvm/relax/frontend/nn/core.py:
##########
@@ -67,6 +67,8 @@
 
 
 _DEFAULT_DTYPE = "float32"
+# If a shape is specified as a string `name`, we create a `tvm.tir.Var(name, "int64")`
+ShapeVar = Union[int, str, tir.PrimExpr]

Review Comment:
   let us still inline `Union[int, str, tir.PrimExpr]` since `ShapeVar` can mean different things(e.g. a variable



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Unity][nnModule] Dynamic shape support in nn Module [tvm]

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen merged PR #16284:
URL: https://github.com/apache/tvm/pull/16284


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Unity][nnModule] Dynamic shape support in nn Module [tvm]

Posted by "CharlieFRuan (via GitHub)" <gi...@apache.org>.
CharlieFRuan commented on code in PR #16284:
URL: https://github.com/apache/tvm/pull/16284#discussion_r1444750422


##########
python/tvm/relax/frontend/nn/core.py:
##########
@@ -67,6 +67,8 @@
 
 
 _DEFAULT_DTYPE = "float32"
+# If a shape is specified as a string `name`, we create a `tvm.tir.Var(name, "int64")`
+ShapeVar = Union[int, str, tir.PrimExpr]

Review Comment:
   Would `ShapeInputType` be better, with a more detailed documentation above it? I am worried that if more `nn.Module` are going to have dynamic shapes in `python/tvm/relax/frontend/nn/modules.py`, `Union[int, str, tir.PrimExpr]` would be repeated in too many places... Right now it is only `Embedding` and `Linear`.



##########
python/tvm/relax/frontend/nn/core.py:
##########
@@ -67,6 +67,8 @@
 
 
 _DEFAULT_DTYPE = "float32"
+# If a shape is specified as a string `name`, we create a `tvm.tir.Var(name, "int64")`
+ShapeVar = Union[int, str, tir.PrimExpr]

Review Comment:
   Would `ShapeInputType` be better, with a more detailed comment above it? I am worried that if more `nn.Module` are going to have dynamic shapes in `python/tvm/relax/frontend/nn/modules.py`, `Union[int, str, tir.PrimExpr]` would be repeated in too many places... Right now it is only `Embedding` and `Linear`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org