View Source tflite_beam_interpreter_builder (tflite_beam v1.0.0)

Build an interpreter capable of interpreting model.

Summary

Functions

Attach a delegate to the builder, with the default decline policy.

Attach a delegate to every interpreter this builder goes on to build.

Build the interpreter with the InterpreterBuilder.

Sets the number of CPU threads to use for the interpreter. Returns ok on success, {error, Reason} on error.

Functions

add_delegate(Builder, Delegate)

-spec add_delegate(reference(), reference()) -> ok | {error, binary()}.

Attach a delegate to the builder, with the default decline policy.

Equivalent to add_delegate(Builder, Delegate, #{}).

add_delegate(Builder, Delegate, Opts)

-spec add_delegate(reference(), reference(), map()) -> ok | {error, binary()}.

Attach a delegate to every interpreter this builder goes on to build.

The delegate is applied in the order delegates were added, and it has to outlive every interpreter built from this builder -- which is why there is no way to detach or delete one. Holding the reference is not required: the builder and each interpreter keep the delegate alive for as long as they need it.

Keyword Parameters

build(Builder, Interpreter)

-spec build(reference(), reference()) -> ok | {ok, delegate_declined} | {error, binary()}.

Build the interpreter with the InterpreterBuilder.

Note: all Interpreters should be built with the InterpreterBuilder, which allocates memory for the Interpreter and does various set up tasks so that the Interpreter can read the provided model.

Returns {ok, delegate_declined} when a delegate added with on_decline => fallback could not take the graph and the interpreter was built without it. See add_delegate/3.

new(Tflite_beam_flatbuffer_model, Resolver)

-spec new(#tflite_beam_flatbuffer_model{initialized :: boolean(),
                                        minimum_runtime :: binary(),
                                        ref :: reference()} |
          reference(),
          reference()) ->
             {ok, reference()} | {error, binary()}.

New InterpreterBuilder

set_num_threads(Builder, NumThreads)

-spec set_num_threads(reference(), integer()) -> ok | {error, binary()}.

Sets the number of CPU threads to use for the interpreter. Returns ok on success, {error, Reason} on error.

NumThreads follows TfLite: -1 asks the runtime to choose, 0 means the same as 1, and anything below -1 is refused. The spec said pos_integer(), which excluded both of the first two.