Skip to content

Commit 63395e9

Browse files
Michael Gschwindfacebook-github-bot
authored andcommitted
Verbosity control for export
Summary: Verbosity control for export Reviewed By: kimishpatel Differential Revision: D55374748
1 parent cde514c commit 63395e9

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

examples/models/llama2/export_llama_lib.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
logging.basicConfig(level=logging.INFO, format=FORMAT)
4747

4848
pkg_name = __name__
49+
verbosity_setting = None
4950

5051

5152
def set_pkg_name(name: str) -> None:
@@ -57,6 +58,15 @@ def get_resource_path(resource_name) -> str:
5758
return pkg_resources.resource_filename(pkg_name, resource_name)
5859

5960

61+
def set_verbosity(val):
62+
global verbosity_setting
63+
verbosity_setting = val
64+
65+
66+
def verbose_export():
67+
return verbosity_setting
68+
69+
6070
@dataclass
6171
class EmbeddingQuantOptions:
6272
is_per_channel: bool = True
@@ -240,7 +250,8 @@ def quantize(
240250
from torchao.quantization.quant_api import Int8DynActInt4WeightQuantizer
241251

242252
model = Int8DynActInt4WeightQuantizer(precision=torch_dtype).quantize(model)
243-
print("quantized model:", model)
253+
if verbose_export():
254+
print("quantized model:", model)
244255
return model
245256
elif qmode == "8da4w-gptq":
246257
from torchao.quantization.quant_api import Int8DynActInt4WeightGPTQQuantizer
@@ -448,7 +459,9 @@ def build_args_parser() -> argparse.ArgumentParser:
448459

449460
def canonical_path(path: str, *, dir: bool = False) -> str:
450461

451-
print(f"creating canonical path for {path}")
462+
if verbose_export():
463+
print(f"creating canonical path for {path}")
464+
452465
if not path.startswith("par:"):
453466
return path
454467

@@ -457,7 +470,8 @@ def canonical_path(path: str, *, dir: bool = False) -> str:
457470
return path[4:]
458471
else:
459472
return_val = pkg_resources.resource_filename(pkg_name, path[4:])
460-
print(f"canonical name is: {return_val}")
473+
if verbose_export():
474+
print(f"canonical name is: {return_val}")
461475
return return_val
462476

463477

0 commit comments

Comments
 (0)