What's Changed
- Bump Cpp lib to 1.1.0
- Split Module creation to simple
Module::new(path)and a newModuleBuilderthat support all customization and arguments, including newmemory_allocatorandtemp_allocatorargs introduced in the new Cpp version.- let module = Module::from_file_path(path); + let module = Module::new(path); - let module = Module::new( - pte_path, - &[data1_path, data2_path], - Some(LoadMode::File), - /* event_tracer */ None); + let module = ModuleBuilder::new(ptr_path) + .data_files(&[data1_path, data2_path]), + .load_mode(LoadMode::File) + .build();
- Change list EValue constructors to accept pointer to ArrayRef/BoxedEvalueList rather than a slice/BoxedEvalueList-value.
The new API comes from an optimization in the Cpp side (pytorch/executorch#13013), which added another indirection but reduced the size of EValue struct.
Constructing an EValue from&stror&CStrdirectly is no longer possible, asArrayRefmust be allocated somewhere and borrowed to the EValue. UseArrayRef::from_cstrorArrayRef::from_charsand construct the value using the array ref instead.// lists of f64, bool and std::ffi::c_char are simply slices within EValue let list = [42.0, 17.0, 6.0]; - let evalue = EValue::new(list.as_slice()); + let list_ref = ArrayRef::from_slice(list.as_slice); + let evalue = EValue::new(&list); - let evalue = EValue::new(c"hello world!"); + let chars = ArrayRef::from_cstr(c"hello world!"); + let evalue = EValue::new(&chars); // lists of i64, Tensor and optional Tensor are stored in BoxedEvalueList within EValue let (evalue1, evalue2, evalue3) = (EValue::new(42), EValue::new(17), EValue::new(6)); let wrapped_vals = EValuePtrList::new([&evalue1, &evalue2, &evalue3]); let mut unwrapped_vals = storage!(i64, (3)); let list = BoxedEvalueList::new(&wrapped_vals, unwrapped_vals.as_mut()).unwrap(); - let evalue = EValue::new(list); + let evalue = EValue::new(&list);
- Make
DataLoader,MemoryAllocatorandNamedDataMaptraits instead of structs. In the Cpp side these are all base classes, and classes extending them used to implementAsRef<BaseClass>on the Rust side. Traits are more flexible, and allow for functions that consumeself. This change is reverting the opposite change introduced inv0.8.0. - Add
TensorPtr::copy_of
Full Changelog: v0.8.1...v0.9.0