-
Notifications
You must be signed in to change notification settings - Fork 76
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
model.train() Issue #79
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've been attempting to fine-tune a GPT-2 base model using Adapter from OpenDelta. While training the model, I came across this error: element 0 of tensors does not require grad and does not have a grad_fn. Upon investigating the source of the error, I discovered that it occurs after calling the .train() function of the model. Any suggestions on how to resolve this?
Code :
model= GPT2LMHeadModel.from_pretrained('gpt2',device_map=device) tokenizer = GPT2Tokenizer.from_pretrained("gpt2") tokenizer.add_tokens(['<p>']) model.resize_token_embeddings(len(tokenizer)) # Resizing the embedding layer model.gradient_checkpointing_enable() delta_model = AdapterModel(model,bottleneck_dim = 32) delta_model.freeze_module(exclude=["deltas"]) delta_model.log() optimizer = torch.optim.Adam(model.parameters(),lr=1e-4) optimizer.zero_grad() model.train() # Causing the error text = "Random str" input_ids = tokenizer(text, return_tensors='pt') out = model(input_ids['input_ids'].to(device),attention_mask =input_ids['attention_mask'].to(device), labels = input_ids['input_ids'].to(device)) out.loss.backward()
The text was updated successfully, but these errors were encountered: