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

Some tensors share memory #9

Open
martinjingyu opened this issue Nov 29, 2024 · 1 comment
Open

Some tensors share memory #9

martinjingyu opened this issue Nov 29, 2024 · 1 comment

Comments

@martinjingyu
Copy link

I met the same question as #6, and I fixed!

@martinjingyu
Copy link
Author

Open the file "curiosity_redteam/custom_trlx/trlx/trainer/accelerate_base_trainer.py"
Find the method: def save(self, directory: Optional[str] = None, **kwargs):

def save(self, directory: Optional[str] = None, **kwargs):
        """Creates a checkpoint of the optimizer, scheduler and model"""
        dst_dir = directory or self.config.train.checkpoint_dir

        # Manually copy weights to detach shared memory.
        with torch.no_grad():
            self.model.base_model.base_model.model.lm_head.weight = torch.nn.Parameter(self.model.base_model.base_model.model.transformer.wte.weight.clone())
        self.accelerator.save_state(dst_dir, **kwargs)

        if self.config.model.peft_config is not None and self.accelerator.is_main_process:
            # Remove "pytorch_model.bin" because it contains more than necessary,
            # let save_pretrained recreate it with just the value heads.
            model_file = os.path.join(dst_dir, "pytorch_model.bin")
            if os.path.exists(model_file):
                os.remove(model_file)
            self.accelerator.unwrap_model(self.model).save_pretrained(dst_dir)

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

1 participant