MCPcopy
hub / github.com/deepspeedai/DeepSpeed / move_key

Function move_key

deepspeed/runtime/utils.py:1159–1166  ·  view source on GitHub ↗
(state, key)

Source from the content-addressed store, hash-verified

1157 """Move optimizer states to device. Note that this assumes the state structure of DeepSpeed Adam."""
1158
1159 def move_key(state, key):
1160 offload_buf_key = _make_offload_state_key(key)
1161 if offload_buf_key not in state:
1162 state[offload_buf_key] = torch.empty_like(state[key], device=device)
1163 if pin_memory:
1164 state[offload_buf_key] = get_accelerator().pin_memory(state[offload_buf_key])
1165 state[offload_buf_key].copy_(state[key], non_blocking=non_blocking)
1166 state[key].data = state[offload_buf_key]
1167
1168 for _, state in optimizer.state.items():
1169 if "exp_avg" in state:

Callers 1

offload_adam_statesFunction · 0.70

Calls 4

get_acceleratorFunction · 0.90
copy_Method · 0.80
_make_offload_state_keyFunction · 0.70
pin_memoryMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…