Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- newtype ScriptModule = UnsafeScriptModule (ForeignPtr Module)
- newtype RawModule = UnsafeRawModule (ForeignPtr Module)
- type RawIValue = ForeignPtr IValue
- newtype Blob = UnsafeBlob (ForeignPtr (C10Ptr Blob))
- newtype Object = UnsafeObject (ForeignPtr (C10Ptr IVObject))
- newtype Future = UnsafeFuture (ForeignPtr (C10Ptr IVFuture))
- newtype Capsule = UnsafeCapsule (ForeignPtr (C10Ptr Capsule))
- newtype Graph = UnsafeGraph (ForeignPtr (SharedPtr JitGraph))
- data JitGraph = JitGraph {
- graphInputs :: [JitValue]
- graphOutputs :: [JitValue]
- graphNodes :: [JitNode]
- data JitNode = JitNode {
- nodeInputs :: [JitValue]
- nodeOutputs :: [JitValue]
- nodeKind :: String
- data JitValue = JitValue {}
- data IValue
- = IVNone
- | IVTensor Tensor
- | IVDouble Double
- | IVInt Int64
- | IVBool Bool
- | IVTuple [IValue]
- | IVIntList [Int64]
- | IVDoubleList [Double]
- | IVBoolList [Bool]
- | IVString String
- | IVTensorList [Tensor]
- | IVBlob
- | IVGenericList [IValue]
- | IVGenericDict [(IValue, IValue)]
- | IVFuture
- | IVDevice
- | IVObject
- | IVUninitialized
- | IVCapsule
- newModule :: String -> IO RawModule
- saveScript :: ScriptModule -> FilePath -> IO ()
- saveScript' :: RawModule -> FilePath -> IO ()
- data LoadMode
- loadScript :: LoadMode -> FilePath -> IO ScriptModule
- loadScript' :: FilePath -> IO RawModule
- registerParameter :: RawModule -> String -> Tensor -> Bool -> IO ()
- registerModule :: RawModule -> String -> RawModule -> IO ()
- getParameters :: ScriptModule -> [Tensor]
- getParametersIO :: RawModule -> IO [Tensor]
- setParameters :: RawModule -> [Tensor] -> IO ()
- updateParameters :: LoadMode -> ScriptModule -> [Tensor] -> ScriptModule
- getNamedParameters :: ScriptModule -> [(String, Tensor)]
- getNamedBuffers :: ScriptModule -> [(String, Tensor)]
- getNamedAttributes :: ScriptModule -> [(String, IValue)]
- getNamedModules :: ScriptModule -> [(String, ScriptModule)]
- getNamedChildren :: ScriptModule -> [(String, ScriptModule)]
- toScriptModule :: RawModule -> IO ScriptModule
- toRawModule :: ScriptModule -> IO RawModule
- cloneRawModule :: RawModule -> IO RawModule
- data RuntimeMode
- setRuntimeMode :: RawModule -> RuntimeMode -> IO ()
- define :: RawModule -> String -> IO ()
- dumpToStr :: ScriptModule -> Bool -> Bool -> Bool -> IO String
- dumpToStr' :: ScriptModule -> IO String
- runMethod :: ScriptModule -> String -> [IValue] -> IValue
- runMethod1 :: ScriptModule -> String -> IValue -> IValue
- trace :: String -> String -> ([Tensor] -> IO [Tensor]) -> [Tensor] -> IO RawModule
- traceWithParameters :: Parameterized f => String -> (f -> [Tensor] -> IO [Tensor]) -> f -> [Tensor] -> IO RawModule
- traceAsGraph :: ([Tensor] -> IO [Tensor]) -> [Tensor] -> IO Graph
- printGraph :: Graph -> IO String
- printOnnx :: Graph -> IO String
- graphToJitGraph :: Graph -> IO JitGraph
Documentation
newtype ScriptModule Source #
Instances
Show ScriptModule Source # | |
Defined in Torch.Script | |
Parameterized ScriptModule Source # | |
Defined in Torch.Script | |
Castable ScriptModule (ForeignPtr Module) Source # | |
Defined in Torch.Script cast :: ScriptModule -> (ForeignPtr Module -> IO r) -> IO r Source # uncast :: ForeignPtr Module -> (ScriptModule -> IO r) -> IO r Source # | |
HasForward ScriptModule [IValue] IValue Source # | |
Defined in Torch.Script forward :: ScriptModule -> [IValue] -> IValue Source # forwardStoch :: ScriptModule -> [IValue] -> IO IValue Source # |
type RawIValue = ForeignPtr IValue Source #
JitGraph | |
|
JitNode | |
|
Instances
saveScript :: ScriptModule -> FilePath -> IO () Source #
loadScript :: LoadMode -> FilePath -> IO ScriptModule Source #
Load a torchscript file
:: ScriptModule | module |
-> [Tensor] | output |
updateParameters :: LoadMode -> ScriptModule -> [Tensor] -> ScriptModule Source #
:: ScriptModule | module |
-> [(String, Tensor)] | output |
:: ScriptModule | module |
-> [(String, Tensor)] | output |
:: 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.
:: ScriptModule | module |
-> [(String, ScriptModule)] | output |
:: ScriptModule | module |
-> [(String, ScriptModule)] | output |
toScriptModule :: RawModule -> IO ScriptModule Source #
toRawModule :: ScriptModule -> IO RawModule Source #
data RuntimeMode Source #
Instances
Show RuntimeMode Source # | |
Defined in Torch.Script | |
Eq RuntimeMode Source # | |
Defined in Torch.Script (==) :: RuntimeMode -> RuntimeMode -> Bool Source # (/=) :: RuntimeMode -> RuntimeMode -> Bool Source # |
setRuntimeMode :: RawModule -> RuntimeMode -> IO () Source #
dumpToStr' :: ScriptModule -> IO String Source #
:: ScriptModule | module |
-> String | func |
-> IValue | inputs |
-> IValue | output |
:: 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"
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.