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

Fix int8 training #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 2 additions & 7 deletions finetune.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from modeling_chatglm import ChatGLMForConditionalGeneration
import torch
import torch.nn as nn
from peft import get_peft_model, LoraConfig, TaskType
from peft import get_peft_model, prepare_model_for_int8_training, LoraConfig, TaskType
from dataclasses import dataclass, field
import datasets
import os
Expand All @@ -20,11 +20,6 @@ class FinetuneArguments:
lora_rank: int = field(default=8)


class CastOutputToFloat(nn.Sequential):
def forward(self, x):
return super().forward(x).to(torch.float32)


def get_masks_and_position_ids(
seq, seq_len, context_length, device, gmask=False, position_encoding_2d=True
):
Expand Down Expand Up @@ -126,10 +121,10 @@ def main():
model.enable_input_require_grads()
model.is_parallelizable = True
model.model_parallel = True
model.lm_head = CastOutputToFloat(model.lm_head)
model.config.use_cache = (
False # silence the warnings. Please re-enable for inference!
)
model = prepare_model_for_int8_training(model)

# setup peft
peft_config = LoraConfig(
Expand Down