Documentation
¶
Index ¶
- func GetPipeline[T pipelines.Pipeline](s *Session, name string) (T, error)
- func NewPipeline[T pipelines.Pipeline](s *Session, pipelineConfig pipelines.PipelineConfig[T]) (T, error)
- type DownloadOptions
- type FeatureExtractionConfig
- type Session
- func (s *Session) Destroy() error
- func (s *Session) DownloadModel(modelName string, destination string, options DownloadOptions) (string, error)
- func (s *Session) GetFeatureExtractionPipeline(name string) (*pipelines.FeatureExtractionPipeline, error)
- func (s *Session) GetStats() []string
- func (s *Session) GetTextClassificationPipeline(name string) (*pipelines.TextClassificationPipeline, error)
- func (s *Session) GetTokenClassificationPipeline(name string) (*pipelines.TokenClassificationPipeline, error)
- func (s *Session) NewFeatureExtractionPipeline(modelPath string, name string) (*pipelines.FeatureExtractionPipeline, error)
- func (s *Session) NewTextClassificationPipeline(modelPath string, name string, opts ...TextClassificationOption) (*pipelines.TextClassificationPipeline, error)
- func (s *Session) NewTokenClassificationPipeline(modelPath string, name string, opts ...TokenClassificationOption) (*pipelines.TokenClassificationPipeline, error)
- type TextClassificationConfig
- type TextClassificationOption
- type TokenClassificationConfig
- type TokenClassificationOption
- type WithOption
- func WithCoreML(flags uint32) WithOption
- func WithCpuMemArena(enable bool) WithOption
- func WithCuda(options map[string]string) WithOption
- func WithDirectML(deviceID int) WithOption
- func WithInterOpNumThreads(numThreads int) WithOption
- func WithIntraOpNumThreads(numThreads int) WithOption
- func WithMemPattern(enable bool) WithOption
- func WithOnnxLibraryPath(ortLibraryPath string) WithOption
- func WithOpenVINO(options map[string]string) WithOption
- func WithTelemetry() WithOption
- func WithTensorRT(options map[string]string) WithOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetPipeline ¶ added in v0.0.9
GetPipeline can be used to retrieve a pipeline of type T with the given name from the session
func NewPipeline ¶ added in v0.0.9
func NewPipeline[T pipelines.Pipeline](s *Session, pipelineConfig pipelines.PipelineConfig[T]) (T, error)
NewPipeline can be used to create a new pipeline of type T. The initialised pipeline will be returned and it will also be stored in the session object so that all created pipelines can be destroyed with session.Destroy() at once.
Types ¶
type DownloadOptions ¶ added in v0.0.7
type DownloadOptions struct {
AuthToken string
SkipSha bool
Branch string
MaxRetries int
RetryInterval int
ConcurrentConnections int
Verbose bool
}
DownloadOptions is a struct of options that can be passed to DownloadModel
func NewDownloadOptions ¶ added in v0.0.7
func NewDownloadOptions() DownloadOptions
NewDownloadOptions creates new DownloadOptions struct with default values. Override the values to specify different download options.
type FeatureExtractionConfig ¶ added in v0.0.9
type FeatureExtractionConfig = pipelines.PipelineConfig[*pipelines.FeatureExtractionPipeline]
FeatureExtractionConfig is the configuration for a feature extraction pipeline
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session allows for the creation of new pipelines and holds the pipeline already created.
func NewSession ¶
func NewSession(options ...WithOption) (*Session, error)
NewSession is the main entrypoint to hugot and is used to create a new hugot session object. ortLibraryPath should be the path to onnxruntime.so. If it's the empty string, hugot will try to load the library from the default location (/usr/lib/onnxruntime.so). A new session must be destroyed when it's not needed anymore to avoid memory leaks. See the Destroy method. Note moreover that there can be at most one hugot session active (i.e., the Session object is a singleton), otherwise NewSession will return an error.
func (*Session) Destroy ¶
Destroy deletes the hugot session and onnxruntime environment and all initialized pipelines, freeing memory. A hugot session should be destroyed when not neeeded anymore, preferably with a defer() call.
func (*Session) DownloadModel ¶ added in v0.0.7
func (s *Session) DownloadModel(modelName string, destination string, options DownloadOptions) (string, error)
DownloadModel can be used to download a model directly from huggingface. Before the model is downloaded, validation occurs to ensure there is an .onnx and tokenizers.json file. Hugot only works with onnx models.
func (*Session) GetFeatureExtractionPipeline ¶
func (s *Session) GetFeatureExtractionPipeline(name string) (*pipelines.FeatureExtractionPipeline, error)
GetFeatureExtractionPipeline returns a feature extraction pipeline by name. If the name does not exist, it will return an error. Deprecated: use GetPipeline.
func (*Session) GetStats ¶
GetStats returns runtime statistics for all initialized pipelines for profiling purposes. We currently record for each pipeline: the total runtime of the tokenization step the number of batch calls to the tokenization step the average time per tokenization batch call the total runtime of the inference (i.e. onnxruntime) step the number of batch calls to the onnxruntime inference the average time per onnxruntime inference batch call
func (*Session) GetTextClassificationPipeline ¶
func (s *Session) GetTextClassificationPipeline(name string) (*pipelines.TextClassificationPipeline, error)
GetTextClassificationPipeline returns a text classification pipeline by name. If the name does not exist, it will return an error. Deprecated: use GetPipeline.
func (*Session) GetTokenClassificationPipeline ¶
func (s *Session) GetTokenClassificationPipeline(name string) (*pipelines.TokenClassificationPipeline, error)
GetTokenClassificationPipeline returns a token classification pipeline by name. If the name does not exist, it will return an error. Deprecated: use GetPipeline.
func (*Session) NewFeatureExtractionPipeline ¶
func (s *Session) NewFeatureExtractionPipeline(modelPath string, name string) (*pipelines.FeatureExtractionPipeline, error)
NewFeatureExtractionPipeline creates and returns a new feature extraction pipeline object. modelPath should be the path to a folder with the onnx exported transformer model. Name is an identifier for the pipeline (see GetFeatureExtractionPipeline). Deprecated: use NewPipeline
func (*Session) NewTextClassificationPipeline ¶
func (s *Session) NewTextClassificationPipeline(modelPath string, name string, opts ...TextClassificationOption) (*pipelines.TextClassificationPipeline, error)
NewTextClassificationPipeline creates and returns a new text classification pipeline object. modelPath should be the path to a folder with the onnx exported transformer model. Name is an identifier for the pipeline (see GetTextClassificationPipeline). Deprecated: use NewPipeline
func (*Session) NewTokenClassificationPipeline ¶
func (s *Session) NewTokenClassificationPipeline(modelPath string, name string, opts ...TokenClassificationOption) (*pipelines.TokenClassificationPipeline, error)
NewTokenClassificationPipeline creates and returns a new token classification pipeline object. modelPath should be the path to a folder with the onnx exported transformer model. Name is an identifier for the pipeline (see GetTokenClassificationPipeline). Deprecated: use NewPipeline
type TextClassificationConfig ¶ added in v0.0.9
type TextClassificationConfig = pipelines.PipelineConfig[*pipelines.TextClassificationPipeline]
TextClassificationConfig is the configuration for a text classification pipeline
type TextClassificationOption ¶ added in v0.0.9
type TextClassificationOption = pipelines.PipelineOption[*pipelines.TextClassificationPipeline]
TextClassificationOption is an option for a text classification pipeline
type TokenClassificationConfig ¶ added in v0.0.9
type TokenClassificationConfig = pipelines.PipelineConfig[*pipelines.TokenClassificationPipeline]
TokenClassificationConfig is the configuration for a token classification pipeline
type TokenClassificationOption ¶ added in v0.0.9
type TokenClassificationOption = pipelines.PipelineOption[*pipelines.TokenClassificationPipeline]
TokenClassificationOption is an option for a token classification pipeline
type WithOption ¶ added in v0.0.8
type WithOption func(o *ortOptions)
WithOption is the interface for all option functions
func WithCoreML ¶ added in v0.1.0
func WithCoreML(flags uint32) WithOption
WithCoreML Use this function to set the CoreML options flags for the ONNX Runtime configuration. The `flags` parameter represents the CoreML options flags. The `o.coreMLOptions` field in `ortOptions` struct will be set to the provided flags parameter. The `o.coreMLOptionsSet` field in `ortOptions` struct will be set to true.
func WithCpuMemArena ¶ added in v0.0.8
func WithCpuMemArena(enable bool) WithOption
WithCpuMemArena Enable/Disable the usage of the memory arena on CPU. Arena may pre-allocate memory for future usage. Default is true.
func WithCuda ¶ added in v0.1.0
func WithCuda(options map[string]string) WithOption
WithCuda Use this function to set the options for CUDA provider. It takes a pointer to an instance of CUDAProviderOptions struct as input. The options will be applied to the ortOptions struct and the cudaOptionsSet flag will be set to true.
func WithDirectML ¶ added in v0.1.0
func WithDirectML(deviceID int) WithOption
WithDirectML Use this function to set the DirectML device ID for the onnxruntime. By default, this option is not set.
func WithInterOpNumThreads ¶ added in v0.0.8
func WithInterOpNumThreads(numThreads int) WithOption
WithInterOpNumThreads Sets the number of threads used to parallelize execution across separate onnxruntime graph nodes. If unspecified, onnxruntime uses the number of physical CPU cores.
func WithIntraOpNumThreads ¶ added in v0.0.8
func WithIntraOpNumThreads(numThreads int) WithOption
WithIntraOpNumThreads Sets the number of threads used to parallelize execution within onnxruntime graph nodes. If unspecified, onnxruntime uses the number of physical CPU cores.
func WithMemPattern ¶ added in v0.0.8
func WithMemPattern(enable bool) WithOption
WithMemPattern Enable/Disable the memory pattern optimization. If this is enabled memory is preallocated if all shapes are known. Default is true.
func WithOnnxLibraryPath ¶ added in v0.0.5
func WithOnnxLibraryPath(ortLibraryPath string) WithOption
WithOnnxLibraryPath Use this function to set the path to the "onnxruntime.so" or "onnxruntime.dll" function. By default, it will be set to "onnxruntime.so" on non-Windows systems, and "onnxruntime.dll" on Windows.
func WithOpenVINO ¶ added in v0.1.0
func WithOpenVINO(options map[string]string) WithOption
WithOpenVINO Use this function to set the OpenVINO options for the OpenVINO execution provider. The options parameter should be a map of string keys and string values, representing the configuration options. For each key-value pair in the map, the specified option will be set in the OpenVINO execution provider. Once the options are set, the openVINOOptionsSet flag in the ortOptions struct will be set to true. Example usage: WithOpenVINO(map[string]string{"device_type": "CPU", "num_threads": "4"}) This will configure the OpenVINO execution provider to use CPU as the device type and set the number of threads to 4.
func WithTelemetry ¶ added in v0.0.8
func WithTelemetry() WithOption
WithTelemetry Enables telemetry events for the onnxruntime environment. Default is off.
func WithTensorRT ¶ added in v0.1.0
func WithTensorRT(options map[string]string) WithOption
WithTensorRT Use this function to set the options for the TensorRT provider. The options parameter should be a pointer to an instance of TensorRTProviderOptions. By default, the options will be nil and the TensorRT provider will not be used. Example usage:
options := &onnxruntime_go.TensorRTProviderOptions{
DeviceID: 0,
}
WithTensorRT(options)
Note: For the TensorRT provider to work, the onnxruntime library must be built with TensorRT support.