Skip to content

Commit

Permalink
CodeQL: use str.isdigit instead of try/except (#1126)
Browse files Browse the repository at this point in the history
  • Loading branch information
jambayk authored Apr 30, 2024
1 parent 5d08fb7 commit 9e7d426
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
10 changes: 2 additions & 8 deletions olive/passes/onnx/extract_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,8 @@ def pack_weights(
"""

def get_sort_key(module_name: str):
parts = module_name.split(".")
for i, part in enumerate(parts):
try:
# want the layers to be sorted by the number
parts[i] = int(part)
except ValueError:
pass
return parts
# want the layers to be sorted by the number
return [int(part) if part.isdigit() else part for part in module_name.split(".")]

packings = {}
for module_type in module_types:
Expand Down
9 changes: 1 addition & 8 deletions olive/scripts/export_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,7 @@ def parse_args(raw_args):

def get_sort_key(module_name: str):
"""Get the key to sort the module names by."""
parts = module_name.split(".")
for i, part in enumerate(parts):
try:
# want the layers to be sorted by the number
parts[i] = int(part)
except ValueError:
pass
return parts
return [int(part) if part.isdigit() else part for part in module_name.split(".")]


def int4_block_quant(float_weight: "NDArray", block_size: int, is_symmetric: bool):
Expand Down

0 comments on commit 9e7d426

Please sign in to comment.