Skip to content

Conversation

m0rt3nlund
Copy link

@m0rt3nlund m0rt3nlund commented Jul 28, 2025

Hi!

This is my attempt to upgrade the deps and be able to use the latest Ort and ONNX version.
Hopefully my approach does not affect performance, my own tests suggest its still as fast.

Would be nice if someone with actual rust competence can verify my approaches :)

But at least it works :)

Copy link
Collaborator

@mortont mortont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions/nits but overall looks good


/// A faster (unsafe) way of creating an Array from an Erlang binary
fn initialize_from_raw_ptr<T>(ptr: *const T, shape: &[Ix]) -> ArrayViewMut<T, IxDyn> {
fn initialize_from_raw_ptr<T>(ptr: *const T, shape: &[Ix]) -> ArrayViewMut<'_, T, IxDyn> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lifetime looks unnecessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was suggested by the compiler so I implemented the suggestion.
Would you rather we explicitly define the lifetime for Ix ?

($tensors:expr, $axis:expr, $typ:ty, $ort_tensor_kind:ident) => {{
type ArrayType<'a> = ArrayBase<ViewRepr<&'a $typ>, Dim<IxDynImpl>>;
fn filter(tensor: &OrtexTensor) -> Option<ArrayType> {
fn filter<'a>(tensor: &'a OrtexTensor) -> Option<ArrayType<'a>> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lifetimes can be removed, this is elided at compile time

let tensor = match ty {
ort::TensorElementType::Bfloat16 => {
OrtexTensor::bf16(e.try_extract_tensor::<half::bf16>()?.into_owned())
ort::tensor::TensorElementType::Bfloat16 => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of repetition here, may be worth putting this in a function with a generic. Either way it works fine, just a thought.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good idea, but I am not that provisioned in Rust to to that I think :)

Comment on lines 129 to 145
// for output_descriptor in &session.outputs {
// let output_name: &str = &output_descriptor.name;
// let val = outputs.get(output_name).expect(
// &format!(
// "Expected {} to be in the outputs, but didn't find it",
// output_name
// )[..],
// );

// let ortextensor: OrtexTensor = val.try_into()?;
// let shape = ortextensor.shape();
// let (dtype, bits) = ortextensor.dtype();

// let collected_output = (ResourceArc::new(ortextensor), shape, dtype, bits);
// collected_outputs.push(collected_output);
// }

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to stay?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants