Git Product home page Git Product logo

Comments (11)

yuslepukhin avatar yuslepukhin commented on June 6, 2024 1

I would use a built-in array module and provide shape and type as separate argument for maximum flexibility.
However, along with that, we should have a capability to return those types as results. And right now, we only return numpy arrays.

I think OrtValue based interfaces can help us. Simpe run() returns numpy.
However, we can add methods to OrtValue to accept other types in python array and convert the result to python arrays as well.

from onnxruntime.

yuslepukhin avatar yuslepukhin commented on June 6, 2024

ORT supports bfloat16 internally. I would think a separate per type approach is not the best way to go. Rather, I would implement a new universal method that does not depend on numpy so much, and also include other types, such as quantized 8 and 4.

from onnxruntime.

xadupre avatar xadupre commented on June 6, 2024

I suggest using run_with_iobinding and make a helper to use run(sess, None, feeds) where is a dictionary dict[str, torch.Tensor].

from onnxruntime.

yuslepukhin avatar yuslepukhin commented on June 6, 2024

IOBinding has its own specifics as to when the input is actually copied to the device.
Also it is cumbersome for every day use.

from onnxruntime.

justinchuby avatar justinchuby commented on June 6, 2024

Thoughts on supporting dlpack protocols? This way we don't need to know if the inputs are torch or numpy or anything else. The data can be shared using the same protocol.

from onnxruntime.

yuslepukhin avatar yuslepukhin commented on June 6, 2024

Thoughts on supporting dlpack protocols? This way we don't need to know if the inputs are torch or numpy or anything else. The data can be shared using the same protocol.

Does it not come with its own set of data type enums that seem to be even more restrictive than numpy?

from onnxruntime.

justinchuby avatar justinchuby commented on June 6, 2024

Hmm. I tested it and there are constraints. dlpack supports all numpy types except for strings. It supports bfloat16 additionally, but not float8 types. Although as a ML data exchange protocol I can foresee float8 support being added.

A major advantage is that it is supported by all major frameworks (numpy, torch, jax, tensorflow, mlx etc.) so ORT can be compatible with many different tensors easily.

from onnxruntime.

justinchuby avatar justinchuby commented on June 6, 2024
import torch
import jax

t = torch.tensor(42, dtype=torch.bfloat16)
jax.dlpack.from_dlpack(t)
Array(42, dtype=bfloat16)

from onnxruntime.

yuslepukhin avatar yuslepukhin commented on June 6, 2024

We can dlpack support, in fact, I have seen some code in pybind referring to dlpack, but I am not seeing it support what we need. Should we not design something that we can own, maintain and deliver what we need?

from onnxruntime.

yuslepukhin avatar yuslepukhin commented on June 6, 2024

It seems, we can extend numpy types support for our needs. See for example a project that implements bfloat16 type and makes it 1st class citizen for numpy. https://github.com/GreenWaves-Technologies/bfloat16/tree/main

from onnxruntime.

justinchuby avatar justinchuby commented on June 6, 2024

There is also https://github.com/jax-ml/ml_dtypes (from Google) that implements all relevant types, which we use in the ONNX IR. Upstreaming seems challenging based on the context this project gave.

from onnxruntime.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.