Store
public struct Store
A key-value based parameter store.
-
Declaration
Swift
public struct OpenFlag : OptionSet -
Declaration
Swift
public struct Codec : OptionSet -
Read a type-erased tensor from the store.
Declaration
Swift
public func read(_ key: String, kind: DeviceKind? = nil, codec: Codec = []) -> NNC.AnyTensor?Parameters
keyThe key corresponding to that particular tensor.
-
Read only shape of a tensor from the store.
Declaration
Swift
public func read(like key: String) -> AnyTensor?Parameters
likeThe key corresponding to that particular tensor.
-
Retrieve codec for a particular key. It must be a tensor to make sense of this.
Declaration
Swift
public func codec(for key: String) -> Codec?Parameters
keyThe key corresponding to a particular tensor.
-
Read a tensor from the store into tensor variable from dynamic graph.
Declaration
Swift
@discardableResult public func read(_ key: String, variable: DynamicGraph_Any, kind: DeviceKind? = nil, codec: Codec = []) -> BoolParameters
keyThe key corresponding to that particular tensor.
variableThe tensor variable to be initialized with.
-
Declaration
Swift
public enum ModelReaderResult -
Declaration
Swift
public enum ModelReadError : Error -
Read parameters into a given model.
Declaration
Swift
public func read( _ key: String, model: Model, strict: Bool, codec: Codec = [], reader: ((String, DataType, TensorFormat, TensorShape) -> ModelReaderResult)? = nil ) throwsParameters
keyThe key corresponding to a particular model.
modelThe model to be initialized with parameters from a given key.
strictWhen this is true, will throw error if any parameters are missing.
codecThe codec for potential encoded parameters.
readerYou can customize your reader to load parameter with a different name etc.
-
Read parameters into a given model.
Declaration
Swift
@inlinable public func read( _ key: String, model: Model, codec: Codec = [], reader: ((String, DataType, TensorFormat, TensorShape) -> ModelReaderResult)? = nil )Parameters
keyThe key corresponding to a particular model.
modelThe model to be initialized with parameters from a given key.
codecThe codec for potential encoded parameters.
readerYou can customize your reader to load parameter with a different name etc.
-
Read parameters into a given model builder.
Declaration
Swift
@inlinable public func read( _ key: String, model: AnyModelBuilder, strict: Bool, codec: Codec = [], reader: ((String, DataType, TensorFormat, TensorShape) -> ModelReaderResult)? = nil ) throwsParameters
keyThe key corresponding to a particular model.
modelThe model builder to be initialized with parameters from a given key.
strictWhen this is true, will throw error if any parameters are missing.
codecThe codec for potential encoded parameters.
readerYou can customize your reader to load parameter with a different name etc.
-
Read parameters into a given model builder.
Declaration
Swift
@inlinable public func read( _ key: String, model: AnyModelBuilder, codec: Codec = [], reader: ((String, DataType, TensorFormat, TensorShape) -> ModelReaderResult)? = nil )Parameters
keyThe key corresponding to a particular model.
modelThe model builder to be initialized with parameters from a given key.
codecThe codec for potential encoded parameters.
readerYou can customize your reader to load parameter with a different name etc.
-
Read parameters into a given model.
Declaration
Swift
@inlinable public func read( _ key: String, model: AnyModel, strict: Bool, codec: Codec = [], reader: ((String, DataType, TensorFormat, TensorShape) -> ModelReaderResult)? = nil ) throwsParameters
keyThe key corresponding to a particular model.
modelThe model to be initialized with parameters from a given key.
strictWhen this is true, will throw error if any parameters are missing.
codecThe codec for potential encoded parameters.
readerYou can customize your reader to load parameter with a different name etc.
-
Read parameters into a given model.
Declaration
Swift
@inlinable public func read( _ key: String, model: AnyModel, codec: Codec = [], reader: ((String, DataType, TensorFormat, TensorShape) -> ModelReaderResult)? = nil )Parameters
keyThe key corresponding to a particular model.
modelThe model to be initialized with parameters from a given key.
codecThe codec for potential encoded parameters.
readerYou can customize your reader to load parameter with a different name etc.
-
Declaration
Swift
public enum ModelWriteError : Error -
Write a tensor variable to the store.
Declaration
Swift
public func write(_ key: String, variable: DynamicGraph_Any, strict: Bool, codec: Codec = []) throwsParameters
keyThe key corresponding to a particular tensor.
variableThe tensor variable to be persisted.
strictWhether check error.
-
Write a tensor variable to the store.
Declaration
Swift
@inlinable public func write(_ key: String, variable: DynamicGraph_Any, codec: Codec = [])Parameters
keyThe key corresponding to a particular tensor.
variableThe tensor variable to be persisted.
-
Declaration
Swift
public enum ModelWriterResult -
Write a model to the store.
Declaration
Swift
public func write( _ key: String, model: Model, strict: Bool, codec: Codec = [], writer: ((String, NNC.AnyTensor) -> ModelWriterResult)? = nil ) throwsParameters
keyThe key corresponding to a particular model.
modelThe model where its parameters to be persisted.
strictWhether check error.
writerYou can customize your writer to writer parameter with a different name or skip entirely.
-
Write a model to the store.
Declaration
Swift
@inlinable public func write( _ key: String, model: Model, codec: Codec = [], writer: ((String, NNC.AnyTensor) -> ModelWriterResult)? = nil )Parameters
keyThe key corresponding to a particular model.
modelThe model where its parameters to be persisted.
writerYou can customize your writer to writer parameter with a different name or skip entirely.
-
Retrieve a list of all tensors in this file. This reads from the disk and could take some time to finish.
Declaration
Swift
public var keys: [String] { get } -
Remove one tensor by its key.
Declaration
Swift
public func remove(_ key: String) -
Remove all tensors from the store. This also vacuums the store to minimize its size.
Declaration
Swift
public func removeAll() -
Explicit vacuum the database.
Declaration
Swift
public func vacuum() -
Wrap the database ops in a transaction.
Declaration
Swift
public func withTransaction<Result>(_ closure: () throws -> Result) rethrows -> Result
Store Structure Reference