"tf32":False, "gradient_checkpointing":True, "gradient_checkpointing":False, 'max_seq_length':512,# 'max_target_length':100,# 预测最大长度, 保留字段 'use_fast_tokenizer':False, Expand Down 6 changes: 3 additions & 3 deletions6config/sft_config_lora.py ...
情况一,如果是全量微调,我们根据Embedding模块索引得到的inputs_embeds是需要梯度的非叶子结点,可以修改(inputs_embeds实际上是Embedding模块中对应tensor的副本,修改inputs_embeds并不用担心会改变Embedding模块本身的参数); 情况二,如果是PEFT,Embedding模块是冻结的,即requires_grad=False,那么索引得到的inputs_embeds仍然...
classBertEncoder(nn.Module):defforward(args):...fori,layer_moduleinenumerate(self.layer):...ifself.gradient_checkpointingandself.training:ifuse_cache:logger.warning("`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`...")use_cache=Falsedefcreate_custom_forwar...
) if os.path.exists('checkpoints/') is False: os.mkdir('checkpoints') torch.save(model.state_dict(), 'checkpoints/epoch_'+str(epoch)+'.pt') #Test the model on validation data. train_acc,train_loss=test_model(model,train_dataloader) val_acc,val_loss=test_model(mo...
🐛 Describe the bug I am comparing the memory cost between use_reentrant=False and use_reentrant=True when using gradient checkpointing. When set use_reentrant=False, i find the peak memory is exactly the same with the one without using g...
禁用use_cache:在训练过程中将use_cache设置为False,这样可以避免与梯度检查点的冲突。但请注意,这可能会降低生成任务的效率。 调整梯度检查点的配置:根据模型的复杂度和内存限制,调整梯度检查点的配置,以减少内存使用量,同时尽量保持模型的性能。 查阅官方文档和社区:访问Hugging Face的官方文档和社区论坛,了解其他用户...
如果不需要与非Checkpointing过程相比较的确定性输出,则向Checkpointing或Checkpointing顺序提供preserve_rng_state=False,以在每个Checkpointing期间省略存储和恢复rng状态。存储逻辑将当前设备和所有cuda张量参数的设备的RNG状态保存并恢复到run_fn。但是,逻辑无法预测用户是否会将张量移动到run_fn自身内的新...
但是我们还需要设置一下的参数:冻结量化参数以防止训练,在所有归一化层和 LM 头中使用FP32(未量化),以确保模型的稳定性如果使用梯度检查点,需要配置model.enable_input_require_grad()for name, param in model.named_parameters(): # freeze base model's layers param.requires_grad = False# cast...
falsemax_train_epochs = 12train_batch_size = 4gradient_checkpointing = truenetwork_train_unet_only = truenetwork_train_text_encoder_only = falselearning_rate = 0.0001unet_lr = 0.0005text_encoder_lr = 0.00005lr_scheduler = "cosine"lr_warmup_steps = 0optimizer_type = "Prodigy"network_module...
根据Checkpointing操作的运行时间,隐藏和恢复RNG状态的逻辑可能会导致适度的性能损失(moderate performance hit)。如果不需要与非Checkpointing过程相比较的确定性输出,则向Checkpointing或Checkpointing顺序提供preserve_rng_state=False,以在每个Checkpointing期间省略存储和恢复rng状态。