Skip to content

Commit

Permalink
Upgrade candle which includes metal support (#20)
Browse files Browse the repository at this point in the history
* update candle nn and core

* default device type

* update readme
  • Loading branch information
jimexist authored Feb 1, 2024
1 parent 8d793a4 commit 9d01b98
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Options:
--output-dir <OUTPUT_DIR>
output directory, under which the input image will be generating a subdirectory [default: ./surya_output]
--device <DEVICE_TYPE>
[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
Expand Down
16 changes: 13 additions & 3 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DeviceType>,

#[arg(long, help = "whether to enable verbose mode")]
verbose: bool,
Expand Down Expand Up @@ -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)?;
Expand Down

0 comments on commit 9d01b98

Please sign in to comment.