pub struct InferInput {
pub input_name: String,
pub input_shape: Vec<usize>,
pub input_data: DataType,
}
Expand description
Represents a single input tensor for inference requests.
InferInput
bundles together:
- the input name (as expected by the model),
- the input shape (tensor dimensions),
- and the input data (wrapped in
DataType
).
§Examples
Creating manually:
use truston::client::io::{InferInput, DataType};
let input = InferInput::new(
"input_tensor".into(),
vec![2, 2],
DataType::F32(vec![0.1, 0.2, 0.3, 0.4]),
);
assert_eq!(input.input_shape, vec![2, 2]);
Creating directly from an ndarray:
use ndarray::array;
use truston::client::io::InferInput;
let arr = array![[1.0f32, 2.0], [3.0, 4.0]].into_dyn();
let input = InferInput::from_ndarray("matrix_input", arr);
assert_eq!(input.input_shape, vec![2, 2]);
§Notes
- MVP1: only
ArrayD<T>
withVec<T>: IntoInferData
is supported. - MVP2: future versions may support zero-copy or borrowed buffers for better performance.
Fields§
§input_name: String
§input_shape: Vec<usize>
§input_data: DataType
Implementations§
Source§impl InferInput
impl InferInput
Sourcepub fn from_ndarray<T>(name: impl Into<String>, arr: ArrayD<T>) -> Self
pub fn from_ndarray<T>(name: impl Into<String>, arr: ArrayD<T>) -> Self
Examples found in repository?
More examples
examples/infer_test.rs (line 10)
8async fn run_infer(client: Arc<TritonRestClient>) -> Result<(), TrustonError> {
9 let arr_ids: ArrayD<i64> = ArrayD::zeros(IxDyn(&[32, 128]));
10 let input_ids = InferInput::from_ndarray("input_ids", arr_ids);
11
12 let arr_attention_mask: ArrayD<i64> = ArrayD::zeros(IxDyn(&[32, 128]));
13 let input_attention_mask = InferInput::from_ndarray("attention_mask", arr_attention_mask);
14
15 let inputs = vec![input_ids, input_attention_mask];
16
17 let _ = client.infer(inputs, "hierarchical_clf").await?;
18 Ok(())
19}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for InferInput
impl RefUnwindSafe for InferInput
impl Send for InferInput
impl Sync for InferInput
impl Unpin for InferInput
impl UnwindSafe for InferInput
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more