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

distilbert tensor size issue . #175

Open
sahlebrahim opened this issue May 4, 2024 · 1 comment
Open

distilbert tensor size issue . #175

sahlebrahim opened this issue May 4, 2024 · 1 comment

Comments

@sahlebrahim
Copy link

sahlebrahim commented May 4, 2024

for epoch in range(NUM_EPOCHS):
    
    model.train()
    
    for batch_idx, batch in enumerate(train_loader):
        
        ### Prepare data
        input_ids = batch['input_ids'].to(DEVICE)
        attention_mask = batch['attention_mask'].to(DEVICE)
        labels = batch['labels'].to(DEVICE)

        ### Forward
        outputs = model(input_ids, attention_mask=attention_mask, labels=labels) **
        loss, logits = outputs['loss'], outputs['logits']

this is returning error :

RuntimeError: The size of tensor a (3157) must match the size of tensor b (512) at non-singleton dimension 1

i did everything just like the book says

@rasbt
Copy link
Owner

rasbt commented May 11, 2024

Hi there,
this is an odd error. I just tried it on my computer and it seems to work for me. Based on your error message, it seems like the input may be too long for the supported context length of the model. Can you check that it has been indeed correctly truncated to 512?

Screenshot 2024-05-11 at 8 44 42 AM

(The code is here for your convenience: https://github.com/rasbt/machine-learning-book/blob/main/ch16/ch16-part3-bert.ipynb)

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

2 participants