Skip to content

Instantly share code, notes, and snippets.

@shinh
Last active July 21, 2019 08:49
Show Gist options
  • Save shinh/c66a8d549f4b2de46929f49aeb8bba7b to your computer and use it in GitHub Desktop.
Save shinh/c66a8d549f4b2de46929f49aeb8bba7b to your computer and use it in GitHub Desktop.
$ python3 ./scripts/elichikacheck.py mutable.py

すると out/elichika_tmp/tmp_mutable/model.onnx と out/elichika_tmp/tmp_immutable/model.onnx が出ます

$ pip3 install --user netron
$ netron out/elichika_tmp/tmp_mutable/model.onnx

とかしてグラフを見るとか、

$ python3 -c 'import onnx ; import sys ; print(onnx.helper.printable_graph(onnx.load(sys.argv[1]).graph))' out/elichika_tmp/tmp_mutable/model.onnx
graph  (
  %in_0_L.-1[INT64]
) {
  %@C_3 = Constant[value = <Scalar Tensor []>]()
  %in_0_st_L.8 = Add(%in_0_L.-1, %@C_3)
  %#returned_value_mutable.py[L.9] = ChainerSequenceCreate(%in_0_st_L.8, %in_0_st_L.8)
  %in_0_st_cp_out_0_L.-1 = Identity(%in_0_st_L.8)
  return %in_0_st_L.8, %in_0_st_cp_out_0_L.-1
}

などと中を見ることできます。 ChainerSequenceCreate は意味がないノードなので無視してください

import chainer
class Inplace(chainer.Chain):
def forward(self, v):
x = v
x += 3
return x, v
from chainer_compiler.elichika import testtools
import numpy as np
def main():
testtools.generate_testcase(Inplace(), [np.array(10)], subname='mutable')
testtools.generate_testcase(Inplace(), [10], subname='immutable')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment