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

[Feat] bits and bytes config 추가 #36

Merged
merged 2 commits into from
Nov 22, 2024
Merged

Conversation

jagaldol
Copy link
Contributor

📝 Summary

config 설정을 통해 bits and bytes 패키지로 양자화를 할 수 있도록 기능을 추가하였습니다.

✅ Checklist

  • 관련 이슈가 명시되어 있습니다.
  • 테스트가 완료되었습니다.
  • [ ] 문서 업데이트가 포함되었습니다.
  • 코드 리뷰를 위한 사전 검토를 완료했습니다.

📄 Description

  • config.yaml에 bnb 설정이 추가되었습니다.
bnb:
  load_in_8bit: false
  load_in_4bit: false
  bnb_4bit_compute_dtype: "float16" # float16, float32, bfloat16 / 4 bit 양자화 데이터의 계산 데이터 타입
  bnb_4bit_use_double_quant: false # true 시 더블 양자화(메모리 사용량 감소, 시간 더 걸림)
  bnb_4bit_quant_type: "nf4" # nf4, fp4

4bit 및 8bit 양자화를 할 수 있으며, 4bit 양자화 시 세부 로직을 선택할 수 있습니다.

  • wandb 로그에 실험 이름안에 양자화 타입도 기록하도록 변경하였습니다.
    • 4bit/8bit/no_qunatization 중 하나로 타입이 기록됩니다.
  • inference.py에서도 양자화 설정을 통해 기 학습된 모델을 불러오게 하였습니다.
    • 멘토님의 조언에 따르면 양자화하여 학습한 모델을 추론도 양자화하여 진행하는 것이 성능 손실이 일어나지 않는다고 하여 이부분을 개선하였습니다.

💡 Notice (Optional)

from_pretrained로 모델을 불러올 때 BitsAndBytesConfig 객체를 quantization_config로 넣으면 양자화 설정이 로드되며 학습 속도가 느려지는 현상을 발견하였습니다.

따라서, load_model 함수에서 load_in_4bit 혹은 load_in_8bit 둘 중 하나가 True 인 경우(양자화가 필요한 경우) 에만 quantization_config 객체를 만들도록 하였습니다.(없다면 None을 넣어 평범하게 모델을 불러와 학습 속도에 영향을 주지 않습니다.)

추가적으로 torch_dtype도 config에서 수정가능하게 파라미터화 시켰습니다.

🔗 Related Issue(s)

#23

@jagaldol jagaldol requested a review from Usunwoo November 22, 2024 04:34
@jagaldol jagaldol self-assigned this Nov 22, 2024
Copy link
Contributor

@gsgh3016 gsgh3016 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다!! 기본 베이스라인 코드 리팩토링이 잘 되어서 기능 추가가 비교적 수월해진 것 같습니다 :)

@jagaldol jagaldol merged commit 145e155 into main Nov 22, 2024
3 checks passed
@jagaldol jagaldol deleted the feature/23-bits-and-bytes branch November 22, 2024 05:40
Copy link
Contributor

@Usunwoo Usunwoo left a comment

Choose a reason for hiding this comment

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

모델 학습과 추론 시 같은 양자화를 적용하게 잘 작성해 놨네요! 아주 좋습니다~~😀

@canolayoo78 canolayoo78 added Priority: Medium 적절한 시기에 처리해야 할 작업 Type: Enhancement 기능 개선 작업 labels Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: Medium 적절한 시기에 처리해야 할 작업 Type: Enhancement 기능 개선 작업
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants