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)
| 142 | |
| 143 | /// Returns the best available device at `ordinal` index (in case of multiple GPUs), or CPU if `force_cpu` is true. |
| 144 | pub 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 | |
| 161 | pub fn load_safetensors_from_model(path: &Path) -> Result<Vec<std::path::PathBuf>> { |
| 162 | log::info!("loading tensors from {} ...", "model.safetensors"); |
no outgoing calls