Multi-GPU Tensor Initialization Question #11774
-
The documentation advises the usage of 'type_as' when initializing new tensors in multi-gpu settings:
The example shows a case where a new tensor is initialized inside a LightningModule forward function:
Presumably x is a tensor that has already been initialized on the target gpu. My question is what to do in the case where we want to initialize a new tensor on the target gpu, and we do not have access to a tensor that has already been initialized on the target gpu? For example, how does one properly initialize a new tensor when it is created inside a Dataset constructor that is instantiated during LightningDataModule setup()?
where:
Will using type_as on the new tensor initialize the data on the target gpu?
Or is a different approach necessary? (e.g. register_buffer()) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
if it's part of the dataset, it's already moved to the target device when a batch is created while iterating over the dataset. |
Beta Was this translation helpful? Give feedback.
if it's part of the dataset, it's already moved to the target device when a batch is created while iterating over the dataset.