Commit Graph

18 Commits

Author SHA1 Message Date
Carson M.
9bada329a8 feat: msrv 1.72 2025-01-13 17:26:32 -06:00
Carson M.
c8bd1cc027 fix: TensorRef::from_array_view lifetime 2024-12-21 00:59:38 -06:00
Carson M.
1dbad54248 refactor!: precompute value dtype/memory info
Breaking because `extract_tensor_*` now returns `&[i64]` for dimensions, and `dtype()` and `memory_info()` also return references.

Each tensor extract call not only had multiple FFI calls to determine the `ValueType`, but also had to determine `MemoryInfo` to ensure the data was CPU-accessible. Since neither the data type or memory location can *change* for a given value, it doesn't make sense to compute this on each extract call; it's better to compute it once, when we create the `Value` (and we often already have the types created by this time, so little FFI is actually required).

This should make `extract_tensor_raw` zero-alloc, most benefitting usages of `IoBinding`/`OutputSelector`. This does mean usages of `Value` without ever extracting said value (like HF Transformers hidden state outputs which go ignored) incur slightly more overhead, but the tradeoff of having less overhead at extraction time seems worth it.
2024-11-15 18:08:42 -06:00
Carson M.
d4f82fc50e refactor!: undo The Flattening 2024-11-12 22:19:15 -06:00
Carson M.
82dcf8410e refactor!: put ptr() behind trait 2024-11-12 13:39:58 -06:00
Carson M.
cdd6be7a66 chore(*): format code 2024-10-14 00:41:21 -05:00
Carson M.
1f6f436117 fix: ValueRef(Mut) should clone ValueInner 2024-10-01 11:33:23 -05:00
Carson M.
359a051419 refactor!: remove redundant error checks; more useful downcast messages
Many of the ORT APIs are hardcoded to actually *never* return a failure status, despite returning `*mut OrtStatus`, probably for consistency (which is appreciated!)
For `ort`, this means almost every API requires a ? or unwrap, even if it will never fail. Notably, this includes all functions on `MemoryInfo`.
This commit makes many of these functions return `T` instead of `Result<T>`.

Additionally, I found that all of the `downcast` methods on `Value` just panic if the type is not downcastable - that's bad! Now a nice `Display` is implemented for `ValueType`, and the downcast functions actually return errors. Extraction methods also have better error messages.

Also in this commit: checking if memory is CPU accessible the *correct* way instead of matching AllocationDevices.
2024-09-14 17:15:06 -05:00
Carson M.
2d26f1f363 refactor: opaque Error
Shaves off the `thiserror` dependency and should improve compile times slightly.
Unfortunately this does mean we can't match on `Error` anymore, though I'm not sure if that was ever useful to begin with.
2024-08-31 15:17:06 -05:00
Carson M.
b5e90741ab test: more Value tests 2024-08-05 17:30:00 -05:00
Carson M.
dc79ade39d chore: more readable imports
when auto-importing, rust-analyzer seems to only do absolute imports on odd-numbered days and Tuesdays, falling back to crate:: imports otherwise. this commit adds some consistency.
2024-07-01 00:05:35 -05:00
Carson M.
c64b8ea990 refactor: usability
aka The Cleanening, part 2

- Add clearer documentation and examples for more things.
- Rework string tensors by introducing `PrimitiveTensorElementType` for primitive (i.e. f32) types, and again re-implementing `IntoTensorElementType` for `String`. This allows string tensors to be used via `Tensor<String>` instead of exclusively via `DynTensor`. Additionally, string tensors no longer require an `Allocator` to be created (which didn't make sense, since string data in Rust can only ever be stored on the CPU anyway). This also now applies to `Map`s, since their data also needed to be on the CPU anyway. (`Sequence`s are currently unaffected because I think a custom allocator could be useful for them?)
- Rework the `IoBinding` interface, and add an example clarifying the intended usage of it (ref #209). Thanks to AAce from the pyke Discord for pointing out the mutability issue in the old interface, which should be addressed now.
- Refactor `OperatorDomain::add` from the slightly-nicer-looking-but-more-confusing `fn<T>(t: T)` to just `fn<T>()` to further enforce the fact that `Operator`s are zero-sized.
- Maps can now have `String` keys.
- Remove some unused errors.
2024-06-21 15:37:39 -05:00
Carson M.
cedeb55909 fix: swap upcast <-> downcast to match actual meaning
closes #191
2024-04-25 08:36:53 -05:00
Carson M.
0efd08222e chore: replace possible unwraps with more descriptive expects 2024-04-13 18:56:13 -05:00
Carson M
393f25f6e4 feat: value specialization (#178) 2024-03-27 19:45:41 -05:00
Carson M.
3064d6bac2 style: fix formatting 2024-02-22 19:54:56 -06:00
Carson M.
6e7c051a7a feat: custom ops & mutable tensors 2024-02-22 19:53:51 -06:00
Carson M.
763acc3499 refactor: split up Value impls 2024-02-21 23:21:25 -06:00