
TorchScript: statically-typed graph representation of PyTorch models
Source:R/geron_w4d_native.R
morie_geron_torchscript.RdTraces an op sequence into a static graph (shapes frozen at each node), then verifies by replay.
Examples
W <- diag(2)
morie_geron_torchscript(list(list(kind = "linear", param = W),
list(kind = "relu")), matrix(c(1, -1), 1, 2))
#> $graph
#> $graph[[1]]
#> $graph[[1]]$index
#> [1] 0
#>
#> $graph[[1]]$kind
#> [1] "linear"
#>
#> $graph[[1]]$in_shape
#> [1] 1 2
#>
#> $graph[[1]]$out_shape
#> [1] 1 2
#>
#> $graph[[1]]$op
#> $graph[[1]]$op$kind
#> [1] "linear"
#>
#> $graph[[1]]$op$param
#> [,1] [,2]
#> [1,] 1 0
#> [2,] 0 1
#>
#>
#>
#> $graph[[2]]
#> $graph[[2]]$index
#> [1] 1
#>
#> $graph[[2]]$kind
#> [1] "relu"
#>
#> $graph[[2]]$in_shape
#> [1] 1 2
#>
#> $graph[[2]]$out_shape
#> [1] 1 2
#>
#> $graph[[2]]$op
#> $graph[[2]]$op$kind
#> [1] "relu"
#>
#>
#>
#>
#> $output
#> [,1] [,2]
#> [1,] 1 0
#>
#> $replay
#> [,1] [,2]
#> [1,] 1 0
#>
#> $max_diff
#> [1] 0
#>
#> $n_nodes
#> [1] 2
#>
#> $shapes
#> $shapes[[1]]
#> $shapes[[1]][[1]]
#> [1] 1 2
#>
#> $shapes[[1]][[2]]
#> [1] 1 2
#>
#>
#> $shapes[[2]]
#> $shapes[[2]][[1]]
#> [1] 1 2
#>
#> $shapes[[2]][[2]]
#> [1] 1 2
#>
#>
#>
#> $estimate
#> [1] 0
#>
#> $n
#> [1] 1
#>
#> $method
#> [1] "Shape-specialised tracing of an op sequence into a static graph, verified by replay"
#>