mirror of
https://github.com/modelscope/modelscope.git
synced 2026-09-01 19:49:03 +02:00
@@ -192,7 +192,7 @@ if config['model']['type'] == 'chatglm6b':
|
||||
model_config['model']['prefix_projection'] = args.prefix_projection
|
||||
|
||||
tokenizer = ChatGLMTokenizer.from_pretrained(model_dir, trust_remote_code=True)
|
||||
model = Model.from_pretrained(model_dir, cfg_dict=model_config, device_map='auto')
|
||||
model = Model.from_pretrained(model_dir, cfg_dict=model_config)
|
||||
|
||||
if args.ptuning_checkpoint is not None:
|
||||
# Evaluation
|
||||
@@ -213,7 +213,7 @@ if args.pre_seq_len is not None:
|
||||
# P-tuning v2
|
||||
model = model.half()
|
||||
model.transformer.prefix_encoder.float()
|
||||
elif not args.use_lora:
|
||||
else:
|
||||
# Finetune
|
||||
model = model.float()
|
||||
|
||||
@@ -367,8 +367,6 @@ model.gradient_checkpointing_enable()
|
||||
if config['model']['type'] == 'chatglm6b':
|
||||
model.enable_input_require_grads()
|
||||
|
||||
# import torch
|
||||
# model = torch.nn.DataParallel(model).cuda()
|
||||
trainer = Seq2SeqTrainer(
|
||||
model=model,
|
||||
cfg_file='./configuration.json',
|
||||
@@ -377,7 +375,6 @@ trainer = Seq2SeqTrainer(
|
||||
seed=args.seed,
|
||||
data_collator=data_collator,
|
||||
remove_unused_data=True,
|
||||
device='cpu',
|
||||
cfg_modify_fn=cfg_modify_fn)
|
||||
trainer.tokenizer = tokenizer
|
||||
trainer.train()
|
||||
|
||||
@@ -1267,8 +1267,6 @@ class ChatGLMForConditionalGeneration(ChatGLMPreTrainedModel):
|
||||
shift_labels = labels[..., 1:].contiguous()
|
||||
# Flatten the tokens
|
||||
loss_fct = CrossEntropyLoss(ignore_index=-100)
|
||||
if shift_logits.device != shift_labels.device:
|
||||
shift_labels = shift_labels.to(shift_logits.device())
|
||||
loss = loss_fct(
|
||||
shift_logits.view(-1, shift_logits.size(-1)),
|
||||
shift_labels.view(-1))
|
||||
|
||||
@@ -1003,8 +1003,6 @@ class ChatGLM2ForConditionalGeneration(ChatGLMPreTrainedModel):
|
||||
shift_labels = labels[..., 1:].contiguous()
|
||||
# Flatten the tokens
|
||||
loss_fct = CrossEntropyLoss(ignore_index=-100)
|
||||
if shift_logits.device != shift_labels.device:
|
||||
shift_labels = shift_labels.to(shift_logits.device())
|
||||
loss = loss_fct(
|
||||
shift_logits.view(-1, shift_logits.size(-1)),
|
||||
shift_labels.view(-1))
|
||||
|
||||
@@ -26,6 +26,7 @@ class CheckpointProcessor:
|
||||
trainer: The trainer instance.
|
||||
output_dir: The target folder used in inference.
|
||||
"""
|
||||
model = trainer.unwrap_module(trainer.model)
|
||||
config = trainer.cfg
|
||||
|
||||
# override pipeline by tasks name after finetune done,
|
||||
@@ -38,7 +39,7 @@ class CheckpointProcessor:
|
||||
config['pipeline'] = {'type': config['task']}
|
||||
|
||||
self.copy_files_and_dump_config(trainer, output_dir, config,
|
||||
'*.bin')
|
||||
self._bin_file(model))
|
||||
|
||||
@staticmethod
|
||||
def copy_files_and_dump_config(trainer, output_dir, config, bin_file):
|
||||
|
||||
@@ -232,7 +232,7 @@ class EpochBasedTrainer(BaseTrainer):
|
||||
# A logic to fit the current code
|
||||
# Put a DDPHook in if launcher is provided.
|
||||
if 'hooks' not in self.cfg.train:
|
||||
self.cfg.train['hooks'] = []
|
||||
self.cfg.train['hooks'] = ConfigDict([])
|
||||
self.cfg.train['hooks'].append({
|
||||
'type': 'DDPHook',
|
||||
'launcher': self.launcher
|
||||
|
||||
Reference in New Issue
Block a user