You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by "haoyang9804 (via GitHub)" <gi...@apache.org> on 2023/09/06 13:54:11 UTC
[GitHub] [tvm] haoyang9804 opened a new pull request, #15683: Fix a bug caused by PyTorch instance_norm when the input shape is [1,1,1,2]
haoyang9804 opened a new pull request, #15683:
URL: https://github.com/apache/tvm/pull/15683
Fix [Issue 15282](https://github.com/apache/tvm/issues/15282)
--
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
[GitHub] [tvm] haoyang9804 commented on a diff in pull request #15683: Fix a bug caused by PyTorch instance_norm when the input shape is [1,1,1,2]
Posted by "haoyang9804 (via GitHub)" <gi...@apache.org>.
haoyang9804 commented on code in PR #15683:
URL: https://github.com/apache/tvm/pull/15683#discussion_r1318198104
##########
python/tvm/relay/frontend/pytorch.py:
##########
@@ -4424,7 +4424,10 @@ def _create_typed_const(data, dtype):
dtype should be a TVM dtype"""
if dtype == "float64":
- typed_data = _expr.const(np.float64(data), dtype=dtype)
+ if len(data) == 1:
+ typed_data = _expr.const(np.array([np.float64(data)]), dtype=dtype)
+ else:
+ typed_data = _expr.const(np.float64(data), dtype=dtype)
Review Comment:
Thanks! I have submitted a issue to Numpy community [here](https://github.com/numpy/numpy/issues/24661).
--
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
[GitHub] [tvm] haoyang9804 commented on a diff in pull request #15683: Fix a bug caused by PyTorch instance_norm when the input shape is [1,1,1,2]
Posted by "haoyang9804 (via GitHub)" <gi...@apache.org>.
haoyang9804 commented on code in PR #15683:
URL: https://github.com/apache/tvm/pull/15683#discussion_r1318540556
##########
python/tvm/relay/frontend/pytorch.py:
##########
@@ -4424,7 +4424,11 @@ def _create_typed_const(data, dtype):
dtype should be a TVM dtype"""
if dtype == "float64":
- typed_data = _expr.const(np.float64(data), dtype=dtype)
+ typed_data = np.float64(data)
+ if np.isscalar(typed_data):
+ typed_data = _expr.const(np.asarray(data, dtype="float64"), dtype=dtype)
+ else:
+ typed_data = _expr.const(typed_data, dtype=dtype)
Review Comment:
True. Thanks for your reminder. Have changed the patch
--
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
[GitHub] [tvm] echuraev commented on a diff in pull request #15683: Fix a bug caused by PyTorch instance_norm when the input shape is [1,1,1,2]
Posted by "echuraev (via GitHub)" <gi...@apache.org>.
echuraev commented on code in PR #15683:
URL: https://github.com/apache/tvm/pull/15683#discussion_r1318295972
##########
python/tvm/relay/frontend/pytorch.py:
##########
@@ -4424,7 +4424,10 @@ def _create_typed_const(data, dtype):
dtype should be a TVM dtype"""
if dtype == "float64":
- typed_data = _expr.const(np.float64(data), dtype=dtype)
+ if len(data) == 1:
+ typed_data = _expr.const(np.array([np.float64(data)]), dtype=dtype)
+ else:
+ typed_data = _expr.const(np.float64(data), dtype=dtype)
Review Comment:
Thank you! In this case, something like `typed_data = _expr.const(np.asarray(data, dtype="float64"), dtype=dtype)` might be the best solution for this problem.
--
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
[GitHub] [tvm] echuraev commented on a diff in pull request #15683: Fix a bug caused by PyTorch instance_norm when the input shape is [1,1,1,2]
Posted by "echuraev (via GitHub)" <gi...@apache.org>.
echuraev commented on code in PR #15683:
URL: https://github.com/apache/tvm/pull/15683#discussion_r1318534607
##########
python/tvm/relay/frontend/pytorch.py:
##########
@@ -4424,7 +4424,11 @@ def _create_typed_const(data, dtype):
dtype should be a TVM dtype"""
if dtype == "float64":
- typed_data = _expr.const(np.float64(data), dtype=dtype)
+ typed_data = np.float64(data)
+ if np.isscalar(typed_data):
+ typed_data = _expr.const(np.asarray(data, dtype="float64"), dtype=dtype)
+ else:
+ typed_data = _expr.const(typed_data, dtype=dtype)
Review Comment:
I think that the following code also should work:
```suggestion
typed_data = _expr.const(np.asarray(data, dtype="float64"), dtype=dtype)
```
--
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
[GitHub] [tvm] haoyang9804 commented on pull request #15683: Fix a bug caused by PyTorch instance_norm when the input shape is [1,1,1,2]
Posted by "haoyang9804 (via GitHub)" <gi...@apache.org>.
haoyang9804 commented on PR #15683:
URL: https://github.com/apache/tvm/pull/15683#issuecomment-1708513363
cc @vvchernov @echuraev
--
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
[GitHub] [tvm] haoyang9804 commented on a diff in pull request #15683: Fix a bug caused by PyTorch instance_norm when the input shape is [1,1,1,2]
Posted by "haoyang9804 (via GitHub)" <gi...@apache.org>.
haoyang9804 commented on code in PR #15683:
URL: https://github.com/apache/tvm/pull/15683#discussion_r1318267944
##########
python/tvm/relay/frontend/pytorch.py:
##########
@@ -4424,7 +4424,10 @@ def _create_typed_const(data, dtype):
dtype should be a TVM dtype"""
if dtype == "float64":
- typed_data = _expr.const(np.float64(data), dtype=dtype)
+ if len(data) == 1:
+ typed_data = _expr.const(np.array([np.float64(data)]), dtype=dtype)
+ else:
+ typed_data = _expr.const(np.float64(data), dtype=dtype)
Review Comment:
Hi Egor. I got a [feedback](https://github.com/numpy/numpy/issues/24661#issuecomment-1709676592) from Numpy community. Seems that using `np.float64` is not a wise decision here. `np.asarray(..., dtype="float64")` is preferable here, advised by the community.
--
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
[GitHub] [tvm] echuraev commented on a diff in pull request #15683: Fix a bug caused by PyTorch instance_norm when the input shape is [1,1,1,2]
Posted by "echuraev (via GitHub)" <gi...@apache.org>.
echuraev commented on code in PR #15683:
URL: https://github.com/apache/tvm/pull/15683#discussion_r1318118522
##########
python/tvm/relay/frontend/pytorch.py:
##########
@@ -4424,7 +4424,10 @@ def _create_typed_const(data, dtype):
dtype should be a TVM dtype"""
if dtype == "float64":
- typed_data = _expr.const(np.float64(data), dtype=dtype)
+ if len(data) == 1:
+ typed_data = _expr.const(np.array([np.float64(data)]), dtype=dtype)
+ else:
+ typed_data = _expr.const(np.float64(data), dtype=dtype)
Review Comment:
I read your updates in the issue, thank you for detailed description. Here it looks like a workaround above numpy bug. I think that the best way to fix this issue is to create an issue or a PR in the numpy repo with fix.
Currently, this implementation won't work after fixing the bug in numpy. My suggestion is to create an issue or PR with fix to numpy repository and at the same time change the current implementation in the following way:
```suggestion
typed_data = np.float64(data)
if np.isscalar(typed_data):
typed_data = _expr.const(np.array([typed_data]), dtype=dtype)
else:
typed_data = _expr.const(typed_data, dtype=dtype)
```
This code should work also after fixing the bug in Numpy.
--
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
[GitHub] [tvm] echuraev merged pull request #15683: Fix a bug caused by PyTorch instance_norm when the input shape is [1,1,1,2]
Posted by "echuraev (via GitHub)" <gi...@apache.org>.
echuraev merged PR #15683:
URL: https://github.com/apache/tvm/pull/15683
--
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