Skip to content
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

[WIP] remove redundant / unused code #3

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

linziyi96
Copy link
Contributor

@linziyi96 linziyi96 commented Jul 26, 2023

This PR marks a series of changes to replace copy-pasted code with import / inheritance to improve maintainability. The update plan and progress is listed as follows. It is NOT ready to be merged at this moment.

  • [In progress] accessory/model/LLM/llama*.py: Organize the common LLaMA backbone codes.
  • [Done] accessory/model/peft.py: Implement Lora*Linear layers by inheritance.
  • [TODO] accessory/util/misc.py: Remove unused methods.
  • [TODO] accessory/data/falcon*.py: Haven't looked too much but diff is within one screen (code is about 200 lines each)
  • [TODO] accessory/main_pretrain.py, accessory/main_finetune.py: It is not quite clear to me what is the main difference between pretrain and finetune.
  • [TODO] accessory/engine_pretrain.py accessory/engine_finetune.py: Same as above.

@linziyi96 linziyi96 changed the title [WIP] remove redundant code [WIP] remove redundant / unused code Jul 26, 2023
@linziyi96 linziyi96 self-assigned this Jul 26, 2023
linziyi96 added a commit that referenced this pull request Aug 2, 2023
It is probably safer to keep CLIP at its original precision (e.g., fp16)
regardless of the autocast setting: Some casting (e.g., from fp16 to
bf16) may be lossy and can potentially harm the pre-trained model.

Keep the changes to llama.py only at this moment since a lot of copy-
pasted codes may be refactored in the future (#3).
linziyi96 added a commit that referenced this pull request Aug 4, 2023
…ze. (#16)

* temp save

* quick fix of demo memory issue

* Refactor tensor creation dtype / device control.

This commit makes two changes during model creation:
1. Decouples promote_trainable_params_to_fp32 from model __init__. This
   is to avoid casting to fp32 to save memory in inference-only mode
   (#4).
2. Use a context manager to manage default tensor type change. In the
   previous version, the default tensor type is reset to
   torch.FloatTensor after creating the vision model, which is
   technically incorrect and should be the previous default tensor type
   instead. We implement our own context manager because the official
   context managers seem to be incomplete at this time (PyTorch 2.0.1):
   No dtype manager is provided and set_default_device is ineffective to
   the torch.Tensor calls which are used in fairscale.

* Change CLIP dtype management in llama.py

It is probably safer to keep CLIP at its original precision (e.g., fp16)
regardless of the autocast setting: Some casting (e.g., from fp16 to
bf16) may be lossy and can potentially harm the pre-trained model.

Keep the changes to llama.py only at this moment since a lot of copy-
pasted codes may be refactored in the future (#3).

* Respect args.precision when saving checkpoints.

* Support checkpoint merge

Checkpoint merge is suported in misc/tensor_parallel.py. Merge requires
that the checkpoint_mp_world_size % mp_world_size == 0. Support for
split (i.e., when mp_world_size % checkpoint_mp_world_size == 0) and
redistribute (for general mp_world_size and checkpoint_mp_world_size
values) will be added in the future.

Also changing multi_turn demo to use the new loading function with merge
support.

* move printing trainable params

* move training model creation back to cpu

Closes #15, #13
kriskrisliu added a commit that referenced this pull request Aug 19, 2023
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.

1 participant