Skip to content

Commit 6fbd0ae

Browse files
authored
DOC: document missing parameters in load_accelerator_state, find_executable_batch_size, and send_to_device (#4051)
Three public API functions were missing parameters from their docstrings: - load_accelerator_state(): dataloaders was a required parameter with no documentation despite being present in the function signature. - find_executable_batch_size(): reduce_batch_size_fn was undocumented. It allows users to provide a custom batch size reduction strategy instead of the default multiply-by-0.9 behavior. - send_to_device(): non_blocking and skip_keys were both undocumented. non_blocking enables async GPU transfers; skip_keys lets callers exclude specific dict keys from device transfer.
1 parent 4929d1e commit 6fbd0ae

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/accelerate/checkpointing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ def load_accelerator_state(
204204
A list of optimizer instances
205205
schedulers (`List[torch.optim.lr_scheduler._LRScheduler]`):
206206
A list of learning rate schedulers
207+
dataloaders (`List[torch.utils.data.DataLoader]`):
208+
A list of dataloader instances used in your program
207209
process_index (`int`):
208210
The current process index in the Accelerator state
209211
scaler (`torch.amp.GradScaler`, *optional*):

src/accelerate/utils/memory.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ def find_executable_batch_size(
132132
A function to wrap
133133
starting_batch_size (`int`, *optional*):
134134
The batch size to try and fit into memory
135+
reduce_batch_size_fn (`callable`, *optional*):
136+
A function to determine the new batch size after an out-of-memory error. If not
137+
provided, the batch size is multiplied by 0.9 on each failure. The function takes
138+
no arguments and should return the new (reduced) batch size as an `int`.
135139
136140
Example:
137141

src/accelerate/utils/operations.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ def send_to_device(tensor, device, non_blocking=False, skip_keys=None):
142142
The data to send to a given device.
143143
device (`torch.device`):
144144
The device to send the data to.
145+
non_blocking (`bool`, *optional*, defaults to `False`):
146+
If `True`, the transfer to the device is performed asynchronously, which can overlap
147+
data movement with computation. Only effective when the device supports it (e.g. CUDA).
148+
skip_keys (`str` or `List[str]`, *optional*):
149+
A key or list of keys in a dictionary `tensor` whose values should not be sent to
150+
the given `device`. Entries with these keys are left on their original device.
145151
146152
Returns:
147153
The same data structure as `tensor` with all tensors sent to the proper device.

0 commit comments

Comments
 (0)