Press J to jump to the feed. Press question mark to learn the rest of the keyboard shortcuts
Log In
Found the internet!

Python Education

r/learnpython

5
pinned by moderators
Posted by4 days ago
5
49 comments
261
3
2
Posted by4 hours ago
2
6 comments
Vote
Posted by42 minutes ago

I am trying to train GPT2 model on a task as in this notebook : Colab notebook

I am getting the following error :

ValueError: Expected input batch_size (1140) to match target batch_size (632).

The relevant code is as follows :

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
device = torch.device('cpu')
for epoch in range(max_epochs): model.train() total_loss = 0 batch_count = 0
for batch_input, batch_output in train_loader:
    batch_size_actual = batch_input.size(0)

    # Check if the batch sizes are different and skip the incomplete batch
    if batch_size_actual != batch_size:
        continue

    batch_input = batch_input.to(device)
    batch_output = batch_output.to(device)
Vote
0 comments
Vote
Posted by57 minutes ago

https://media.discordapp.net/attachments/1106163304688259102/1106243388342284358/Screenshot_20230511-113607-870.png

Here's the image. It keeps saying that my file or directory for "advertise_master" isn't here but it clearly is. I've tried moving it around and nothing, can anyone please just help me with this?

Vote
1 comment

About Community

Subreddit for posting questions and asking for general advice about your python code.
Created Oct 2, 2009

708k

Members

586

Online

Top 1%

Ranked by Size

r/learnpython Rules

1.
Be polite.
2.
Posts to this subreddit must be requests for help learning python.
3.
Replies on this subreddit must be pertinent to the question OP asked.
4.
No advertising. No blogs/tutorials/videos/books/recruiting attempts.
5.
No replies copy / pasted from ChatGPT or similar.

Code Hosting/Formatting

Post your code on these websites and include the link in your thread, or click on the button below to find out how to properly format code and include it in your submission text.

Helpful posting resources

Please check out few of these links to see how to properly ask a software development related questions.

Related Subreddits

r/Python

1,126,821 members

r/django

111,077 members

r/flask

78,874 members

r/programming

5,409,178 members

r/learnprogramming

3,816,149 members

r/dailyprogrammer

237,011 members

Commenting Guidelines

  • Try to guide OP to a solution instead of providing one directly.

  • Provide links to related resources.

  • Answer the question and highlight side-issues if any exist.

  • Don't "answer and run", be prepared to respond to follow up questions.

  • Proofread your answers for clarity and correctness.

  • Be polite.

Posting Guidelines

  • Try out suggestions you get and report back.

  • SSCCE Keep your code Short, Self Contained, Correct (Compilable) and provide Example

  • Include the error you get when running the code, if there is one.

  • Ensure your example is correct. Either the example compiles cleanly, or causes the exact error message about which you want help.

  • Avoid posting a lot of code in your posts.

  • Posting homework assignments is not prohibited if you show that you tried to solve it yourself.

Moderators

Moderator list hidden. Learn More