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

Minor device settable edit #251

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
run: python prepro_tinyshakespeare.py

- name: Train model
run: python train_gpt2.py
run: python train_gpt2.py --device cpu

- name: Compile training and testing program
run: make test_gpt2 train_gpt2
Expand Down
5 changes: 5 additions & 0 deletions train_gpt2.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ def write_tokenizer(enc, filename):
parser.add_argument("--num_iterations", type=int, default=10, help="number of iterations to run")
parser.add_argument("--batch_size", type=int, default=4, help="batch size")
parser.add_argument("--sequence_length", type=int, default=64, help="sequence length")
parser.add_argument("--device", type=str, default=None, help="device to use (e.g., 'cpu', 'cuda:0')")

args = parser.parse_args()
B, T = args.batch_size, args.sequence_length
assert 1 <= T <= 1024
Expand All @@ -339,6 +341,9 @@ def write_tokenizer(enc, filename):
device = "cuda"
elif hasattr(torch.backends, "mps") and torch.backends.mps.is_available():
device = "mps"
# Override with device argument if set
if args.device:
device = args.device
print(f"using device: {device}")

# create a context manager following the desired dtype and device
Expand Down
Loading