Skip to content

[JIT][script] Add matmul(@), pow(**) operator#7648

Merged
jamesr66a merged 4 commits intopytorch:masterfrom
ChunliF:chunli
May 18, 2018
Merged

[JIT][script] Add matmul(@), pow(**) operator#7648
jamesr66a merged 4 commits intopytorch:masterfrom
ChunliF:chunli

Conversation

@ChunliF
Copy link
Contributor

@ChunliF ChunliF commented May 17, 2018

Add matmul(@) operator (#6049)
Add pow(**) operator (#7542)

@jamesr66a jamesr66a changed the title Add matmul(@), pow(**) operator [JIT][script] Add matmul(@), pow(**) operator May 17, 2018
@jamesr66a jamesr66a added the oncall: jit Add this issue/PR to JIT oncall triage queue label May 17, 2018
with self.assertRaisesRegex(NotSupportedError, "unsupported binary operator:"):
@torch.jit.script
def binop(x, y):
# Replace this with another unsupported op when/if it gets supported

This comment was marked as off-topic.

This comment was marked as off-topic.

Copy link
Contributor

@apaszke apaszke left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, but needs some adjustments!

@unittest.skipIf(not PY35, "Python 3.5 needed")
def test_matmul(self):
def func(a, b):
return a @ b

This comment was marked as off-topic.

with self.assertRaisesRegex(NotSupportedError, "unsupported binary operator:"):
@torch.jit.script
def binop(x, y):
# Replace this with another unsupported op when/if it gets supported

This comment was marked as off-topic.

{'<', '>', TK_EQ, TK_LE, TK_GE, TK_NE},
{'+', '-'},
{'*', '/'},
{'*', '/', TK_MATMUL, TK_POW},

This comment was marked as off-topic.

Copy link
Contributor

@zdevito zdevito left a comment

Choose a reason for hiding this comment

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

Thanks! I have a few small bugs to fix, otherwise it is good.

_(TK_UNARY_MINUS, "unary minus", "")
_(TK_UNARY_MINUS, "unary minus", "") \
_(TK_POW, "pow operator", "**") \
_(TK_MATMUL, "matmul operator", "@")

This comment was marked as off-topic.

{'<', '>', TK_EQ, TK_LE, TK_GE, TK_NE},
{'+', '-'},
{'*', '/'},
{'*', '/', TK_MATMUL, TK_POW},

This comment was marked as off-topic.

This comment was marked as off-topic.

ast.Mult: '*',
ast.Div: '/',
}
if PY2:

This comment was marked as off-topic.


def test_pow(self):
def func(a, b):
return a ** b

This comment was marked as off-topic.

_(TK_UNARY_MINUS, "unary minus", "")
_(TK_UNARY_MINUS, "unary minus", "") \
_(TK_POW, "pow operator", "**") \
_(TK_MATMUL, "matmul operator", "@")

This comment was marked as off-topic.

Copy link
Contributor

@zdevito zdevito left a comment

Choose a reason for hiding this comment

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

Looks good!

Copy link
Collaborator

@jamesr66a jamesr66a left a comment

Choose a reason for hiding this comment

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

Small comment about code duplication

test/test_jit.py Outdated
spec = importlib.util.spec_from_file_location('test_matmul_py3', script_path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
fn = module.fn

This comment was marked as off-topic.

@jamesr66a jamesr66a merged commit ec71c68 into pytorch:master May 18, 2018
onnxbot added a commit to onnxbot/onnx-fb-universe that referenced this pull request May 18, 2018
weiyangfb pushed a commit to weiyangfb/pytorch that referenced this pull request Jun 11, 2018
* add matmul(@), pow(**) operator

* fix bug(matmul not in py2) in @ operator

* fix bugs

* add get_fn help func to remove duplication in test_jit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants