Module: base_inference_workflow
Module implementing a base inference workflow.
This class is not meant to be subclassed directly; instead, subclass one of [TGIClientInferenceWorkflow, CSSInferenceWorkflow, BaseClassicInferenceWorkflow]
BaseInferenceWorkflow
Base class for an inference workflow
Source code in src/infernet_ml/workflows/inference/base_inference_workflow.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
__init__(*args, **kwargs)
Constructor. keeps track of arguments passed in.
Source code in src/infernet_ml/workflows/inference/base_inference_workflow.py
do_generate_proof()
Generates proof, which may vary based on proving system. We currently only support EZKL based proving, which does not require proof generation to be defined as part of the inference workflow if the inference from the circuit directly used for proving. Indeed, that is the case for the classic infernet_ml proof service. However, this may change with the usage of optimistic and other eager or lazy proof systems, which we intend to support in the future. By default, will raise NotImplementedError. Override in subclass as needed.
Source code in src/infernet_ml/workflows/inference/base_inference_workflow.py
do_postprocessing(input_data, output_data)
Implement any postprocessing of the model output. By default, this method returns the output data as is.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_data |
Any
|
raw input from user |
required |
output_data |
Any
|
model output |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
postprocessed output |
Source code in src/infernet_ml/workflows/inference/base_inference_workflow.py
do_preprocessing(input_data)
Implement any preprocessing of the raw user input. For example, you may need to apply feature engineering on the input before it is suitable for model inference. By default, this method returns the input data as is.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_data |
Any
|
raw input from user |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
preprocessed input |
Source code in src/infernet_ml/workflows/inference/base_inference_workflow.py
do_run_model(preprocessed_data)
abstractmethod
run model here. preprocessed_data type is left generic since depending on model type Args: preprocessed_data (typing.Any): preprocessed input into model
Returns:
Type | Description |
---|---|
Any
|
typing.Any: result of running model |
Source code in src/infernet_ml/workflows/inference/base_inference_workflow.py
do_setup()
abstractmethod
set up your workflow here. For LLMs, this may be parameters like top_k, temperature for classical LLM, this may be model hyperparams.
Returns: Any
Source code in src/infernet_ml/workflows/inference/base_inference_workflow.py
do_stream(preprocessed_input)
abstractmethod
Implement any streaming logic here. For example, you may want to stream data from OpenAI or any LLM. This method should return the data to be streamed.
Returns:
Type | Description |
---|---|
Iterator[Any]
|
typing.Any: data to be streamed |
Source code in src/infernet_ml/workflows/inference/base_inference_workflow.py
generate_proof()
Generates proof. checks that setup performed before hand.
Source code in src/infernet_ml/workflows/inference/base_inference_workflow.py
inference(input_data, log_preprocessed_data=True)
performs inference. Checks that model is set up before performing inference. Subclasses should implement do_inference.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_data |
Any
|
input from user |
required |
log_preprocessed_data |
bool
|
If True, logs the |
True
|
Raises:
Type | Description |
---|---|
ValueError
|
if setup not called beforehand |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
result of inference |
Source code in src/infernet_ml/workflows/inference/base_inference_workflow.py
setup()
stream(input_data)
Stream data for inference. Subclasses should implement do_stream.