Skip to content

Verbosity control for export #2690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions examples/models/llama2/export_llama_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
logging.basicConfig(level=logging.INFO, format=FORMAT)

pkg_name = __name__
verbosity_setting = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to make this clearly internal, though I don't know if anyone imports this file.

Suggested change
verbosity_setting = None
_verbosity_setting = None

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way for a user to override this, or is it effectively hard-disabled for now?



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


def set_verbosity(val):
global verbosity_setting
verbosity_setting = val


def verbose_export():
return verbosity_setting
Comment on lines +61 to +67
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to clarify the type here. And along with it, verbosity_setting: bool = False above.

Suggested change
def set_verbosity(val):
global verbosity_setting
verbosity_setting = val
def verbose_export():
return verbosity_setting
def set_verbosity(val: bool):
global verbosity_setting
verbosity_setting = val
def verbose_export() -> bool:
return verbosity_setting



@dataclass
class EmbeddingQuantOptions:
is_per_channel: bool = True
Expand Down Expand Up @@ -240,7 +250,8 @@ def quantize(
from torchao.quantization.quant_api import Int8DynActInt4WeightQuantizer

model = Int8DynActInt4WeightQuantizer(precision=torch_dtype).quantize(model)
print("quantized model:", model)
if verbose_export():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the idea is to guard all prints with this, consider adding a custom print function like log_export() that does it internally to simplify the call sites.

print("quantized model:", model)
return model
elif qmode == "8da4w-gptq":
from torchao.quantization.quant_api import Int8DynActInt4WeightGPTQQuantizer
Expand Down Expand Up @@ -448,7 +459,9 @@ def build_args_parser() -> argparse.ArgumentParser:

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

print(f"creating canonical path for {path}")
if verbose_export():
print(f"creating canonical path for {path}")

if not path.startswith("par:"):
return path

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


Expand Down