Skip to content

bug: UnboundLocalError, logger is not defined #307

Closed
@HarikrishnanBalagopal

Description

Bug

Overview

Commit a6d093eb96e62311ffa02cdeb97d78c90fc86e74

This bug happens if there is an exception in parse_arguments function call because the logger is only bound after it

training_args, logger = set_log_level(training_args, __name__)

So the logger variable here is unbound

logger.error(traceback.format_exc())

Steps to reproduce

$ python3 -m tuning.sft_trainer --output_dir foo --use_flash_attn false --bnb_qlora true
Traceback (most recent call last):
  File "/Users/haribala/Documents/code/remote/github.com/foundation-model-stack/fms-hf-tuning/tuning/sft_trainer.py", line 527, in main
    ) = parse_arguments(parser, job_config)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/haribala/Documents/code/remote/github.com/foundation-model-stack/fms-hf-tuning/tuning/sft_trainer.py", line 485, in parse_arguments
    ) = parser.parse_args_into_dataclasses(return_remaining_strings=True)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/haribala/Documents/code/remote/github.com/foundation-model-stack/fms-hf-tuning/.venv/lib/python3.11/site-packages/transformers/hf_argparser.py", line 339, in parse_args_into_dataclasses
    obj = dtype(**inputs)
          ^^^^^^^^^^^^^^^
  File "<string>", line 5, in __init__
  File "/Users/haribala/Documents/code/remote/github.com/foundation-model-stack/fms-hf-tuning/tuning/config/acceleration_configs/quantized_lora_config.py", line 72, in __post_init__
    ensure_nested_dataclasses_initialized(self)
  File "/Users/haribala/Documents/code/remote/github.com/foundation-model-stack/fms-hf-tuning/tuning/config/acceleration_configs/utils.py", line 34, in ensure_nested_dataclasses_initialized
    values = nested_type(*values)
             ^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 5, in __init__
  File "/Users/haribala/Documents/code/remote/github.com/foundation-model-stack/fms-hf-tuning/tuning/config/acceleration_configs/utils.py", line 86, in __post_init__
    super().__post_init__()
  File "/Users/haribala/Documents/code/remote/github.com/foundation-model-stack/fms-hf-tuning/tuning/config/acceleration_configs/quantized_lora_config.py", line 58, in __post_init__
    raise ValueError("quant_type can only be either 'nf4' or 'fp4.")
ValueError: quant_type can only be either 'nf4' or 'fp4.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/haribala/Documents/code/remote/github.com/foundation-model-stack/fms-hf-tuning/tuning/sft_trainer.py", line 631, in <module>
    fire.Fire(main)
  File "/Users/haribala/Documents/code/remote/github.com/foundation-model-stack/fms-hf-tuning/.venv/lib/python3.11/site-packages/fire/core.py", line 143, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/haribala/Documents/code/remote/github.com/foundation-model-stack/fms-hf-tuning/.venv/lib/python3.11/site-packages/fire/core.py", line 477, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
                                ^^^^^^^^^^^^^^^^^^^^
  File "/Users/haribala/Documents/code/remote/github.com/foundation-model-stack/fms-hf-tuning/.venv/lib/python3.11/site-packages/fire/core.py", line 693, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/haribala/Documents/code/remote/github.com/foundation-model-stack/fms-hf-tuning/tuning/sft_trainer.py", line 550, in main
    logger.error(traceback.format_exc())
    ^^^^^^
UnboundLocalError: cannot access local variable 'logger' where it is not associated with a value

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions