mirror of
https://github.com/zebrajr/pytorch.git
synced 2026-01-15 12:15:51 +00:00
Summary: [Stacked commit, only review the last commit] This PR adds support for printing default values in python printing as well as the logic for parsing default values back in using the parser. For simplicity, this PR simply creates a subgraph of the constant expressions and then runs that graph to generate the defaults. A more lightweight approach should be possible later, but would require more machinery. To make reading code in the printer easier, this also add ir_views.h. Similar to tree_views.h these classes can provide views of some commonly used IR nodes that have complicated structure and common operations on that structure. Currently it has only read-only views for prim::If and prim::Loop, but we should eventually add helpers to manipulate If/Loop nodes as well. Pull Request resolved: https://github.com/pytorch/pytorch/pull/14176 Differential Revision: D13198455 Pulled By: zdevito fbshipit-source-id: dc99ab9692804ccaedb60a55040c0b89ac7a6a6d
74 lines
1.5 KiB
Plaintext
74 lines
1.5 KiB
Plaintext
(def
|
|
(ident fn)
|
|
(decl
|
|
(list
|
|
(param
|
|
(ident x)
|
|
(variable (ident Tensor))
|
|
(option))
|
|
(param
|
|
(ident y)
|
|
(variable (ident Tensor))
|
|
(option))
|
|
(param
|
|
(ident z)
|
|
(variable (ident Tensor))
|
|
(option)))
|
|
(option))
|
|
(list
|
|
(assign
|
|
(variable (ident q))
|
|
(None))
|
|
(assign
|
|
(variable (ident q))
|
|
(-
|
|
(+
|
|
(variable (ident x))
|
|
(variable (ident y)))
|
|
(apply
|
|
(.
|
|
(variable (ident z))
|
|
(ident sigmoid))
|
|
(list)
|
|
(list))))
|
|
(expression statement
|
|
(apply
|
|
(variable (ident print))
|
|
(list (variable (ident q)))
|
|
(list)))
|
|
(assign
|
|
(variable (ident w))
|
|
(unary minus
|
|
(variable (ident z))))
|
|
(if
|
|
(and
|
|
(and
|
|
(not (variable (ident x)))
|
|
(not (variable (ident y))))
|
|
(variable (ident z)))
|
|
(list
|
|
(assign
|
|
(variable (ident m))
|
|
(if
|
|
(not (variable (ident z)))
|
|
(variable (ident x))
|
|
(variable (ident y)))))
|
|
(list))
|
|
(while
|
|
(and
|
|
(<
|
|
(variable (ident x))
|
|
(variable (ident y)))
|
|
(>
|
|
(variable (ident y))
|
|
(variable (ident z))))
|
|
(list
|
|
(assign
|
|
(variable (ident q))
|
|
(variable (ident x)))))
|
|
(assert
|
|
(eq (const 1) (const 1))
|
|
(option (string_literal hello)))
|
|
(return
|
|
(list (variable (ident x))))))
|