change double for loop to list comprehension for upgrading speed

#21
Files changed (1) hide show
  1. modeling_hyperclovax.py +6 -6
modeling_hyperclovax.py CHANGED
@@ -465,12 +465,12 @@ class HCXVisionForCausalLM(PreTrainedModel, GenerationMixin):
465
  possible_resolutions = []
466
  if config.anyres:
467
  assert config.max_num_grids > 0
468
- for i in range(1, config.max_num_grids + 1):
469
- for j in range(1, config.max_num_grids + 1):
470
- if i == 1 and j == 1 and not config.use_1x1_grid:
471
- continue
472
- if i * j <= config.max_num_grids:
473
- possible_resolutions.append([i, j])
474
 
475
  possible_resolutions = [
476
  [ys * vision_config.image_size, xs * vision_config.image_size] for ys, xs in possible_resolutions
 
465
  possible_resolutions = []
466
  if config.anyres:
467
  assert config.max_num_grids > 0
468
+ possible_resolutions = [
469
+ [i, j]
470
+ for i in range(1, config.max_num_grids + 1)
471
+ for j in range(1, (config.max_num_grids // i) + 1)
472
+ if not (i == 1 and j == 1 and not config.use_1x1_grid)
473
+ ]
474
 
475
  possible_resolutions = [
476
  [ys * vision_config.image_size, xs * vision_config.image_size] for ys, xs in possible_resolutions