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

Add test without gradient accumulation #841

Merged
merged 8 commits into from
Dec 11, 2024

Conversation

pglusacTT
Copy link
Contributor

Add a new test that does standard batched training without gradient accumulation.
Renames the existing test to specify that it has gradient accumulation.

Closes #806

@pglusacTT pglusacTT linked an issue Dec 5, 2024 that may be closed by this pull request
@pglusacTT pglusacTT marked this pull request as ready for review December 5, 2024 17:48
pred = tt_model(data)[0]
golden_pred = framework_model(data)
assert golden_pred.dtype == dtype
assert compare_with_golden(golden_pred, pred, verify_cfg=VerifyConfig(pcc=0.95))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this PR, there is a unified method for comparing golden output with output of compiled model: linkt to verify. It calls this compare_with_golden but also performs dataformat and some other sanity checks...

In this PR above, you can find examples of its use in tests. It makes things more concise...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need the predictions from the models since I am calculating the loss after this.
Should I change the verify method to make it return the predictions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verify is under development at the moment (by @vkovinicTT), so I wouldn't change it. Let's leave compare_with_golden then...
@vkovinicTT did you plan on adding return for the predictions any time soon?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not diverge and extend the scope of planned changes for the verify refactor, yet. There are not so many training tests, so it's not a big problem at this moment IMO...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't plan on extending it, but I can do that if needed?

@@ -21,6 +21,92 @@
def test_mnist_training():
torch.manual_seed(0)

# Model and data type. To use bfloat16 follow the instructions found at test_forge_vs_torch() in this file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_forge_vs_torch is moving into tt-thomas - it makes sense to copy the instructions here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, done here de73a93

Copy link
Contributor

@pilkicTT pilkicTT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I am not sure if we should keep the old test? We should probably test the gradient accumulation part differently (sort of like a unit test)...

learning_rate = 0.001

# Limit number of batches to run - quicker test
limit_num_batches = 1000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about removing this "parameter" and just run this with higher batch size, i.e. 2048?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MNIST is 60k inputs so with a large batch size we will never reach limit_num_batches. I agree that limit_num_batches can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done here: ae7bee0

@vladimirjovanovicTT
Copy link
Contributor

Also, I am not sure if we should keep the old test? We should probably test the gradient accumulation part differently (sort of like a unit test)...

I agree that it should be reworked, but maybe in a different PR? We can create an issue for this.

@pglusacTT pglusacTT merged commit 10b90b4 into main Dec 11, 2024
6 checks passed
@pglusacTT pglusacTT deleted the pglusac/train_mnist_no_grad_acc branch December 11, 2024 07:50
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

Successfully merging this pull request may close these issues.

Rework mnist training script
5 participants