hasktorch-0.2.0.0: Functional differentiable programming in Haskell
Safe HaskellSafe-Inferred
LanguageHaskell2010

Torch.Script

Synopsis

Documentation

newtype RawModule Source #

Instances

Instances details
Castable RawModule (ForeignPtr Module) Source # 
Instance details

Defined in Torch.Script

Methods

cast :: RawModule -> (ForeignPtr Module -> IO r) -> IO r Source #

uncast :: ForeignPtr Module -> (RawModule -> IO r) -> IO r Source #

newtype Blob Source #

Constructors

UnsafeBlob (ForeignPtr (C10Ptr Blob)) 

Instances

Instances details
Show Blob Source # 
Instance details

Defined in Torch.Script

newtype Object Source #

Instances

Instances details
Show Object Source # 
Instance details

Defined in Torch.Script

newtype Future Source #

Instances

Instances details
Show Future Source # 
Instance details

Defined in Torch.Script

newtype Capsule Source #

Instances

Instances details
Show Capsule Source # 
Instance details

Defined in Torch.Script

data JitGraph Source #

Constructors

JitGraph 

Instances

Instances details
Show JitGraph Source # 
Instance details

Defined in Torch.Script

Eq JitGraph Source # 
Instance details

Defined in Torch.Script

data JitNode Source #

Constructors

JitNode 

Instances

Instances details
Show JitNode Source # 
Instance details

Defined in Torch.Script

Eq JitNode Source # 
Instance details

Defined in Torch.Script

data JitValue Source #

Constructors

JitValue 

Fields

Instances

Instances details
Show JitValue Source # 
Instance details

Defined in Torch.Script

Eq JitValue Source # 
Instance details

Defined in Torch.Script

data LoadMode Source #

Instances

Instances details
Show LoadMode Source # 
Instance details

Defined in Torch.Script

Eq LoadMode Source # 
Instance details

Defined in Torch.Script

loadScript :: LoadMode -> FilePath -> IO ScriptModule Source #

Load a torchscript file

getParameters Source #

Arguments

:: ScriptModule

module

-> [Tensor]

output

getParametersIO Source #

Arguments

:: RawModule

module

-> IO [Tensor]

output

getNamedParameters Source #

Arguments

:: ScriptModule

module

-> [(String, Tensor)]

output

getNamedBuffers Source #

Arguments

:: ScriptModule

module

-> [(String, Tensor)]

output

getNamedAttributes Source #

Arguments

:: ScriptModule

module

-> [(String, IValue)]

output

Load all attributes including training flags This function returns IVObject type as Tensor type. To get Tensor type, use get getNamedParameters and getNamedBuffers.

getNamedModules Source #

Arguments

:: ScriptModule

module

-> [(String, ScriptModule)]

output

data RuntimeMode Source #

Constructors

Eval 
Train 

Instances

Instances details
Show RuntimeMode Source # 
Instance details

Defined in Torch.Script

Eq RuntimeMode Source # 
Instance details

Defined in Torch.Script

dumpToStr Source #

Arguments

:: ScriptModule

module

-> Bool

print_method_bodies

-> Bool

print_attr_values

-> Bool

print_param_values

-> IO String

ouput

runMethod Source #

Arguments

:: ScriptModule

module

-> String

func

-> [IValue]

inputs

-> IValue

output

runMethod1 Source #

Arguments

:: ScriptModule

module

-> String

func

-> IValue

inputs

-> IValue

output

trace Source #

Arguments

:: String

moduleName

-> String

functionName

-> ([Tensor] -> IO [Tensor])

function

-> [Tensor]

inputs

-> IO RawModule

output

traceWithParameters Source #

Arguments

:: Parameterized f 
=> String

module name

-> (f -> [Tensor] -> IO [Tensor])

traced function

-> f

initial parameters

-> [Tensor]

example inputs

-> IO RawModule

torchscript module

This function generates torchscript-module from Parameterized-instance of hasktorch. Usage is below. -- >> let example_inputs = asTensor (4::Float) -- >> init_parameters <- sample MonoSpec -- >> mutableTorchscript <- traceWithParameters MyModule -- (parameters [example_inputs'] -> return [(traced_function parameters example_inputs')]) -- init_parameters -- [example_inputs] -- >> immutableTorchscript <- toScriptModule mutableTorchscript -- >> save immutableTorchscript "torchscript file"

traceAsGraph Source #

Arguments

:: ([Tensor] -> IO [Tensor])

function

-> [Tensor]

inputs

-> IO Graph

output

printOnnx :: Graph -> IO String Source #

Output onnx file from graph. (really experimental implementation) printOnnx uses export_onnx function of libtorch. It outputs following error, because prim::Constant symbol using torchscript does not exist. -- Exception: ONNX export failed: Couldn't export operator prim::Constant -- Defined at: -- Graph we tried to export: -- graph(%0 : Float(), -- %1 : Float()): -- %2 : int = prim::Constant[value=1]() -- %3 : Float() = aten::add(%0, %1, %2) -- return (%3) -- ; type: std::runtime_error On the other hand, torch.onnx.export of python works. onnx's symbol map is in python code. https://github.com/pytorch/pytorch/blob/master/torch/onnx/symbolic_opset9.py

If you need onnx-file, at first make torchscript by trace , then convert torchscript into onnx by python-code.