diff --git a/Cargo.toml b/Cargo.toml index 4f6652a..47efd5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,8 +10,8 @@ default-run = "surya" [dependencies] anyhow = { version = "1.0.79", optional = true } -candle-core = { version = "0.3.2" } -candle-nn = { version = "0.3.2" } +candle-core = { version = "0.3.3" } +candle-nn = { version = "0.3.3" } clap = { version = "4.4.18", features = ["derive"], optional = true } env_logger = { version = "0.11.0" } hf-hub = { version = "0.3.2" } diff --git a/README.md b/README.md index e9b9e0d..ceace8c 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ Options: --output-dir output directory, under which the input image will be generating a subdirectory [default: ./surya_output] --device - [default: cpu] [possible values: cpu, gpu, metal] + device type, if not specified will try to use GPU or Metal [possible values: cpu, gpu, metal] --verbose whether to enable verbose mode -h, --help diff --git a/src/bin/main.rs b/src/bin/main.rs index 1bd5ca1..0df5f1b 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -130,8 +130,12 @@ struct Cli { )] output_dir: PathBuf, - #[arg(long = "device", value_enum, default_value_t = DeviceType::Cpu)] - device_type: DeviceType, + #[arg( + long = "device", + value_enum, + help = "device type, if not specified will try to use GPU or Metal" + )] + device_type: Option, #[arg(long, help = "whether to enable verbose mode")] verbose: bool, @@ -179,7 +183,13 @@ fn main() -> surya::Result<()> { "bbox-area-threshold must be > 0" ); - let device = args.device_type.try_into()?; + let device = match args.device_type { + Some(device_type) => device_type.try_into()?, + None => Device::new_cuda(0) + .or_else(|_| Device::new_metal(0)) + .unwrap_or(Device::Cpu), + }; + debug!("using device {:?}", device); let image_chunks = read_chunked_resized_image(&args.image)?;