Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function load_buffer_on_device #810

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/wrappers/jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,16 @@ impl CModule {
Ok(CModule { c_module })
}

/// Loads a PyTorch saved JIT model from a read instance.
///
/// This function loads the buffer directly on the specified device,
pub fn load_buffer_on_device(buffer: &Vec<u8>, device: Device) -> Result<CModule, TchError> {
let buffer_ptr = buffer.as_ptr() as *const libc::c_char;
let c_module =
unsafe_torch_err!(atm_load_str_on_device(buffer_ptr, buffer.len(), device.c_int()));
Ok(CModule { c_module })
}

/// Performs the forward pass for a model on some specified tensor inputs. This is equivalent
/// to calling method_ts with the 'forward' method name, and returns a single tensor.
pub fn forward_ts<T: Borrow<Tensor>>(&self, ts: &[T]) -> Result<Tensor, TchError> {
Expand Down