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

[Question] finetune LLaVA-1.5 with LoRA.: does not appear to have a file named config.json. #729

Open
yangzian035210 opened this issue Nov 1, 2023 · 4 comments

Comments

@yangzian035210
Copy link

Question

Thanks for your great work! I have a question about finetune LLaVA-1.5 with LoRA:
OSError: /checkpoints/llava-v1.5-13b-lora-v2/checkpoint-6000 does not appear to have a file named config.json.
image

@dhifafaz
Copy link

dhifafaz commented Nov 2, 2023

have you figured it out?

@CiaoHe
Copy link

CiaoHe commented Nov 7, 2023

It seems like we need add a trigger when saving intermediate checkpoint, like the ones after train finished:

if training_args.lora_enable:
    state_dict = get_peft_state_maybe_zero_3(
        model.named_parameters(), training_args.lora_bias
    )
    non_lora_state_dict = get_peft_state_non_lora_maybe_zero_3(
        model.named_parameters()
    )
    if training_args.local_rank == 0 or training_args.local_rank == -1:
        model.config.save_pretrained(training_args.output_dir)
        model.save_pretrained(training_args.output_dir, state_dict=state_dict)
        torch.save(non_lora_state_dict, os.path.join(training_args.output_dir, 'non_lora_trainables.bin'))
else:
    safe_save_model_for_hf_trainer(trainer=trainer,
                                   output_dir=training_args.output_dir)

@CiaoHe
Copy link

CiaoHe commented Nov 7, 2023

I added a custom callback just above the trainer initialize

# save callback
from transformers import TrainerCallback
class SaveCallback(TrainerCallback):
    def on_save(self, args, state, control, **kwargs):
        checkpoint_dir = os.path.join(args.output_dir, 'checkpoint-{}'.format(state.global_step))
        if args.lora_enable:
            state_dict = get_peft_state_maybe_zero_3(
                model.named_parameters(), training_args.lora_bias
            )
            non_lora_state_dict = get_peft_state_non_lora_maybe_zero_3(
                model.named_parameters()
            )
            if args.local_rank in [-1, 0]:
                model.config.save_pretrained(checkpoint_dir)
                model.save_pretrained(checkpoint_dir, state_dict=state_dict)
                torch.save(non_lora_state_dict, os.path.join(checkpoint_dir, 'non_lora_trainables.bin'))

and pass it to the trainer initializing

trainer = LLaVATrainer(model=model,
                tokenizer=tokenizer,
                args=training_args,
                callbacks=[SaveCallback()],
                **data_module)

@wuwu-C
Copy link

wuwu-C commented Apr 20, 2024

hey I met the same problem. Did you solve this?

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

No branches or pull requests

4 participants