Skip to content

[Fix] Fix bugs on traverse_dict#141

Merged
LZHgrla merged 4 commits intoInternLM:mainfrom
LZHgrla:lzh/bug_cfg
Oct 23, 2023
Merged

[Fix] Fix bugs on traverse_dict#141
LZHgrla merged 4 commits intoInternLM:mainfrom
LZHgrla:lzh/bug_cfg

Conversation

@LZHgrla
Copy link
Copy Markdown
Contributor

@LZHgrla LZHgrla commented Sep 25, 2023

Support to reuse the auto-saved configs from mmengine

@pppppM pppppM requested a review from HIT-cwh September 25, 2023 10:00
Comment thread xtuner/model/utils.py
for key, value in d.items():
if isinstance(value, dict):
if 'type' in value and dataclasses.is_dataclass(value['type']):
traverse_dict(value)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

后续遍历可能会增加时间复杂度,虽然traverse的耗时非常少

Copy link
Copy Markdown
Contributor Author

@LZHgrla LZHgrla Sep 26, 2023

Choose a reason for hiding this comment

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

原版代码只做了“一层”嵌套的处理,这个PR主要是为了涵盖class build和torch.float16嵌套“非常深”的情况,要递归到最深层依次做处理。实际耗时基本无感。

以下面为例

  llm=dict(
      pretrained_model_name_or_path='internlm/internlm-7b',
      quantization_config=dict(
          bnb_4bit_compute_dtype='torch.float16',
          bnb_4bit_quant_type='nf4',
          bnb_4bit_use_double_quant=True,
          llm_int8_has_fp16_weight=False,
          llm_int8_threshold=6.0,
          load_in_4bit=True,
          load_in_8bit=False,
          type='transformers.BitsAndBytesConfig'),
      torch_dtype='torch.float16',
      trust_remote_code=True,
      type='transformers.AutoModelForCausalLM.from_pretrained')

在原版代码,torch_dtype='torch.float16',会被处理为torch.float16;但再深一层的bnb_4bit_compute_dtype='torch.float16',,这一行会缺失处理,而导致报错

@pppppM pppppM requested review from HIT-cwh and removed request for HIT-cwh October 23, 2023 07:12
@LZHgrla LZHgrla merged commit e0f688f into InternLM:main Oct 23, 2023
llkn-2 pushed a commit to llkn-2/xtuner that referenced this pull request Jul 31, 2024
* fix traverse_dict bugs

* fix arguments note

* update requirements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants