forked from LaurentMazare/diffusers-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
259fa62
commit 2c8fada
Showing
5 changed files
with
35 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ pub mod models; | |
pub mod pipelines; | ||
pub mod schedulers; | ||
pub mod transformers; | ||
mod utils; | ||
pub mod utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,32 @@ | ||
// A simple wrapper around File::open adding details about the | ||
// problematic file. | ||
use std::path::Path; | ||
use tch::Device; | ||
|
||
pub(crate) fn file_open<P: AsRef<Path>>(path: P) -> anyhow::Result<std::fs::File> { | ||
std::fs::File::open(path.as_ref()).map_err(|e| { | ||
let context = format!("error opening {:?}", path.as_ref().to_string_lossy()); | ||
anyhow::Error::new(e).context(context) | ||
}) | ||
} | ||
|
||
pub struct DeviceSetup { | ||
accelerator_device: Device, | ||
cpu: Vec<String>, | ||
} | ||
|
||
impl DeviceSetup { | ||
pub fn new(cpu: Vec<String>) -> Self { | ||
let accelerator_device = | ||
if tch::utils::has_mps() { Device::Mps } else { Device::cuda_if_available() }; | ||
Self { accelerator_device, cpu } | ||
} | ||
|
||
pub fn get(&self, name: &str) -> Device { | ||
if self.cpu.iter().any(|c| c == "all" || c == name) { | ||
Device::Cpu | ||
} else { | ||
self.accelerator_device | ||
} | ||
} | ||
} |