orik-ss commited on
Commit
1646a4b
·
1 Parent(s): aa78c6d

PPE: lazy calflops import so src loads without accelerate on Space

Browse files
Files changed (1) hide show
  1. D-FINE/src/misc/profiler_utils.py +5 -1
D-FINE/src/misc/profiler_utils.py CHANGED
@@ -5,13 +5,17 @@ Copyright (c) 2024 The D-FINE Authors. All Rights Reserved.
5
  import copy
6
  from typing import Tuple
7
 
8
- from calflops import calculate_flops
 
 
9
 
10
 
11
  def stats(
12
  cfg,
13
  input_shape: Tuple = (1, 3, 640, 640),
14
  ) -> Tuple[int, dict]:
 
 
15
  base_size = cfg.train_dataloader.collate_fn.base_size
16
  input_shape = (1, 3, base_size, base_size)
17
 
 
5
  import copy
6
  from typing import Tuple
7
 
8
+ # calflops is a training-time FLOPs profiler that pulls in `accelerate`. It is not
9
+ # needed for inference, and the deployment image removes `accelerate`, so import it
10
+ # lazily inside stats() to keep the package importable for inference-only use.
11
 
12
 
13
  def stats(
14
  cfg,
15
  input_shape: Tuple = (1, 3, 640, 640),
16
  ) -> Tuple[int, dict]:
17
+ from calflops import calculate_flops
18
+
19
  base_size = cfg.train_dataloader.collate_fn.base_size
20
  input_shape = (1, 3, base_size, base_size)
21