Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade candle which includes metal support #20

Merged
merged 3 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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