Merged
Conversation
ayeganov
reviewed
Aug 22, 2025
scratchgpt/main.py
Outdated
| latest_model_path = get_latest_model_weights_path(args.experiment) | ||
|
|
||
| model = TransformerLanguageModel(NUM_HEADS, tokenizer.vocab_size, N_EMBED, BLOCK_SIZE, NUM_BLOCKS) | ||
| model = model.to(DEVICE) |
Contributor
There was a problem hiding this comment.
Maybe we should fix it in load_model?
Contributor
Author
There was a problem hiding this comment.
Unless you want to change the signature, we can't.
We need to assign model = model.to(DEVICE)
So.. we either just add that line, or we change
def load_model(model_path: str, model: nn.Module, device: torch.device) -> Noneto
def load_model(model_path: str, model: nn.Module, device: torch.device) -> nn.Module
...
return model
But it's messy because we are doing:
else:
print("No model path exists, proceeding with a new model")In my experience, I always have a line like
model = model.to(DEVICE)
after creation
Contributor
There was a problem hiding this comment.
Gotcha - then I think we can remove model.to from load_model and add this line.
Contributor
There was a problem hiding this comment.
But also - we can do return model.to(DEVICE) from load_model. Since we always provide a valid model pointer.
Contributor
Author
There was a problem hiding this comment.
Done.. if you disagree, I don't care
cf9bdf6 to
fd1cde2
Compare
fd1cde2 to
cad5896
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
It moves the model to the same device as all the tensors