-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Allow user to select individual TPU core to train on #1729
Changes from 4 commits
8995fbc
bd9e88c
1daadfa
e4d49d0
0ed38cd
725ef5d
c0a4f9d
f25d516
a93c6bc
b22f485
cdda262
0669ad2
2253b9f
67c5688
ec278d1
100071b
8adb0a9
34f2209
f779d01
dafe174
4c6958e
5c0db30
c7a9b4e
83e5d99
230831e
59e0b49
f22d90d
940f70b
ec300ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,7 @@ def __init__( | |
gpus: Optional[Union[List[int], str, int]] = None, | ||
auto_select_gpus: bool = False, | ||
num_tpu_cores: Optional[int] = None, | ||
tpu_id: Optional[int] = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so I can use only one TPU? not several with indexes like GPU? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not as per my knowledge. xla_distributed only supports 1 or 8 cores. We can't selectively choose the cores. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tpu_id is not needed... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @williamFalcon I have replaced it with |
||
log_gpu_memory: Optional[str] = None, | ||
progress_bar_refresh_rate: int = 1, | ||
overfit_pct: float = 0.0, | ||
|
@@ -321,6 +322,8 @@ def __init__( | |
self.num_tpu_cores = num_tpu_cores | ||
assert num_tpu_cores in [1, 8, None], 'num_tpu_cores can only be 1 or 8' | ||
|
||
self.tpu_id = tpu_id | ||
|
||
if num_processes != 1 and distributed_backend != "ddp_cpu": | ||
rank_zero_warn("num_processes is only used for distributed_backend=\"ddp_cpu\". Ignoring it.") | ||
self.num_processes = num_processes | ||
|
@@ -775,7 +778,10 @@ def fit( | |
self.model = model | ||
|
||
# train | ||
xmp.spawn(self.tpu_train, args=(model,), nprocs=self.num_tpu_cores, start_method=start_method) | ||
if self.tpu_id is not None: | ||
self.tpu_train(self.tpu_id, model) | ||
else: | ||
xmp.spawn(self.tpu_train, args=(model,), nprocs=self.num_tpu_cores, start_method=start_method) | ||
|
||
# load weights if not interrupted | ||
self.load_spawn_weights(model) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this now makes it ONLY possible to train on 1 core no? not multiple cores
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so... @lezwon ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have noticed that if
self.tpu_id
isNone
and I usexmp.spawn
, the model trains at the same speed it trains when all cores are being used. So I assumed that all cores are being used. I could add some logging to confirm. Or just add a conditional forxm.xla_device()
maybe?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ONLY when the user requests a specific TPU index should we use
model.to(xm.xla_device(self.tpu_id))
otherwise, leave it as it was.@Borda we need TPU tests to make sure this PR doesn't break functionality