-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathdeim.rs
More file actions
71 lines (60 loc) · 2.33 KB
/
Copy pathdeim.rs
File metadata and controls
71 lines (60 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use anyhow::Result;
use clap::Args;
use usls::{Config, DType, Device, Scale};
#[derive(Args, Debug)]
pub struct DeimArgs {
/// Scale: n, s, m, b, l
#[arg(long, global = true, default_value = "s")]
pub scale: Scale,
/// Dtype: fp32, fp16, q4f16, etc.
#[arg(long, global = true, default_value = "fp16")]
pub dtype: DType,
/// version: 1, 2
#[arg(long, global = true, default_value = "2", value_parser = clap::value_parser!(u8).range(1..=2))]
pub ver: u8,
/// Device: cpu, cuda:0, mps, coreml, openvino:CPU, etc.
#[arg(long, global = true, default_value = "cpu")]
pub device: Device,
/// Processor device (for pre/post processing)
#[arg(long, global = true, default_value = "cpu")]
pub processor_device: Device,
/// Batch size
#[arg(long, global = true, default_value_t = 1)]
pub batch: usize,
/// Min batch size (TensorRT)
#[arg(long, global = true, default_value_t = 1)]
pub min_batch: usize,
/// Max batch size (TensorRT)
#[arg(long, global = true, default_value_t = 4)]
pub max_batch: usize,
/// num dry run
#[arg(long, global = true, default_value_t = 3)]
pub num_dry_run: usize,
}
pub fn config(args: &DeimArgs) -> Result<Config> {
let config = match (args.ver, &args.scale) {
(1, Scale::S) => Config::deim_dfine_s_coco(),
(1, Scale::M) => Config::deim_dfine_m_coco(),
(1, Scale::L) => Config::deim_dfine_l_coco(),
(1, Scale::X) => Config::deim_dfine_x_coco(),
(2, Scale::A) => Config::deim_v2_atto_coco(),
(2, Scale::F) => Config::deim_v2_femto_coco(),
(2, Scale::P) => Config::deim_v2_pico_coco(),
(2, Scale::N) => Config::deim_v2_n_coco(),
(2, Scale::S) => Config::deim_v2_s_coco(),
(2, Scale::M) => Config::deim_v2_m_coco(),
(2, Scale::L) => Config::deim_v2_l_coco(),
(2, Scale::X) => Config::deim_v2_x_coco(),
_ => anyhow::bail!(
"Unsupported version {} with scale {}. Try v1/v2 with appropriate scales.",
args.ver,
args.scale
),
}
.with_batch_size_min_opt_max_all(args.min_batch, args.batch, args.max_batch)
.with_model_device(args.device)
.with_model_dtype(args.dtype)
.with_num_dry_run_all(args.num_dry_run)
.with_image_processor_device(args.processor_device);
Ok(config)
}