MCPcopy Create free account
hub / github.com/evilsocket/cake / get_inference_device

Function get_inference_device

cake-core/src/utils/mod.rs:144–159  ·  view source on GitHub ↗

Returns the best available device at `ordinal` index (in case of multiple GPUs), or CPU if `force_cpu` is true.

(force_cpu: bool, ordinal: usize)

Source from the content-addressed store, hash-verified

142
143/// Returns the best available device at `ordinal` index (in case of multiple GPUs), or CPU if `force_cpu` is true.
144pub fn get_inference_device(force_cpu: bool, ordinal: usize) -> Result<Device> {
145 if force_cpu {
146 log::debug!("device is forced cpu");
147 Ok(Device::Cpu)
148 } else if cuda_is_available() {
149 log::debug!("device is cuda {ordinal}");
150 Ok(Device::new_cuda(ordinal)?)
151 } else if metal_is_available() {
152 log::debug!("device is metal {ordinal}");
153 Ok(Device::new_metal(ordinal)?)
154 } else {
155 log::debug!("device is cpu");
156 // fallback to cpu if nothing else available
157 Ok(Device::Cpu)
158 }
159}
160
161pub fn load_safetensors_from_model(path: &Path) -> Result<Vec<std::path::PathBuf>> {
162 log::info!("loading tensors from {} ...", "model.safetensors");

Callers 3

from_argsMethod · 0.85

Calls

no outgoing calls