Skip to content

Commit e47a495

Browse files
dsikkakylesayrs
authored andcommitted
Remove click (#1262)
Signed-off-by: Kyle Sayers <kylesayrs@gmail.com>
1 parent 0fbf6d0 commit e47a495

File tree

3 files changed

+0
-86
lines changed

3 files changed

+0
-86
lines changed

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
"numpy>=1.17.0,<2.0",
5555
"requests>=2.0.0",
5656
"tqdm>=4.0.0",
57-
"click>=7.1.2,!=8.0.0", # 8.0.0 blocked due to reported bug
5857
"torch>=1.7.0",
5958
"transformers>4.0,<5.0",
6059
"datasets",

src/llmcompressor/utils/helpers.py

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
Common functions for interfacing with python primitives and directories/files.
44
"""
55

6-
import ast
76
import contextlib
87
import errno
98
import fnmatch
@@ -60,7 +59,6 @@
6059
"tensors_export",
6160
"json_to_jsonl",
6261
"deprecation_warning",
63-
"parse_kwarg_tuples",
6462
"is_package_available",
6563
"import_from_path",
6664
"getattr_chain",
@@ -884,83 +882,6 @@ def deprecation_warning(message: str):
884882
)
885883

886884

887-
def parse_kwarg_tuples(kwargs: tuple) -> Dict:
888-
"""
889-
Convert a tuple of kwargs to a dict of kwargs.
890-
This function is used to enable the click parsing of kwargs.
891-
892-
Example use:
893-
```
894-
@click.command(
895-
context_settings=dict(
896-
ignore_unknown_options=True)
897-
)
898-
@click.argument(...)
899-
@click.option(...)
900-
...
901-
@click.argument("kwargs", nargs=-1, type=click.UNPROCESSED)
902-
def main(..., kwargs):
903-
...
904-
kwargs: Dict[str, Any] = parse_kwarg_tuples(kwargs: Tuple)
905-
```
906-
907-
Example inputs, outputs:
908-
```
909-
input = ('--arg1', 1, 'arg2', 2, '-arg3', 3)
910-
output = parse_kwarg_tuples(input)
911-
output = {'arg1': 1, 'arg2': 2, 'arg3': 3}
912-
```
913-
914-
```
915-
input = ('--arg1', 1, '--args1', 2 , 'arg2', 2, '-arg3', 3)
916-
output = parse_kwarg_tuples(input)
917-
output = {'arg1': [1, 2], 'arg2': 2, 'arg3': 3}
918-
```
919-
920-
:param kwargs: The kwargs to convert. Should be a tuple of alternating
921-
kwargs names and kwargs values e.g.('--arg1', 1, 'arg2', 2, -arg3', 3).
922-
The names can optionally have a '-' or `--` in front of them.
923-
:return: The converted kwargs as a dict.
924-
"""
925-
if len(kwargs) == 0:
926-
return {}
927-
if len(kwargs) % 2 != 0:
928-
raise ValueError(
929-
"kwargs must be a tuple of alternating names and values "
930-
"i.e. the length of kwargs tuple must be even. Received "
931-
f"kwargs: {kwargs}"
932-
)
933-
# names are uneven indices, values are even indices
934-
kwargs_names = kwargs[0::2]
935-
kwargs_values = kwargs[1::2]
936-
# by default kwargs values are strings, so convert them
937-
# to the appropriate type if possible
938-
kwargs_values = list(kwargs_values)
939-
for i, value in enumerate(kwargs_values):
940-
try:
941-
kwargs_values[i] = ast.literal_eval(value)
942-
except Exception as e: # noqa E841
943-
logger.debug(
944-
f"Failed to infer non-string type"
945-
f"from kwarg value: {value}. It will"
946-
f"be left as a string."
947-
)
948-
pass
949-
# remove any '-' or '--' from the names
950-
kwargs_names = [name.lstrip("-") for name in kwargs_names]
951-
processed_kwargs = {}
952-
for kwarg_name, kwarg_value in zip(kwargs_names, kwargs_values):
953-
if kwarg_name in processed_kwargs:
954-
# if the kwarg name is already in the processed kwargs,
955-
# then we should convert the value to a list
956-
if not isinstance(processed_kwargs[kwarg_name], list):
957-
processed_kwargs[kwarg_name] = [processed_kwargs[kwarg_name]]
958-
processed_kwargs[kwarg_name].append(kwarg_value)
959-
else:
960-
processed_kwargs[kwarg_name] = kwarg_value
961-
return processed_kwargs
962-
963-
964885
def is_package_available(
965886
package_name: str,
966887
return_version: bool = False,

tests/llmcompressor/utils/test_helpers.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
flatten_iterable,
1212
getattr_chain,
1313
interpolate,
14-
parse_kwarg_tuples,
1514
validate_str_iterable,
1615
)
1716

@@ -93,11 +92,6 @@ def test_interpolate(x_cur, x0, x1, y0, y1, inter_func, out):
9392
assert abs(out - interpolated) < 0.01
9493

9594

96-
def test_pass_kwargs_tuples():
97-
kwargs = parse_kwarg_tuples(("--input_1", 1, "--input_2", "two", "--input_3", "2"))
98-
assert kwargs == dict(input_1=1, input_2="two", input_3=2)
99-
100-
10195
def test_getattr_chain():
10296
base = SimpleNamespace()
10397
base.a = None

0 commit comments

Comments
 (0)