MCPcopy Create free account
hub / github.com/bitsandbytes-foundation/bitsandbytes / step

Method step

bitsandbytes/optim/optimizer.py:306–341  ·  view source on GitHub ↗

Perform a single optimization step. Arguments: closure (`Callable`, *optional*, defaults to `None`): A closure that reevaluates the model and returns the loss.

(self, closure=None)

Source from the content-addressed store, hash-verified

304
305 @torch.no_grad()
306 def step(self, closure=None):
307 """Perform a single optimization step.
308
309 Arguments:
310 closure (`Callable`, *optional*, defaults to `None`):
311 A closure that reevaluates the model and returns the loss.
312 """
313 loss = None
314 if closure is not None:
315 with torch.enable_grad():
316 loss = closure()
317
318 if not self.initialized:
319 self.check_overrides()
320 self.to_gpu() # needed for fairseq pure fp16 training
321 self.initialized = True
322
323 # if self.is_paged: self.page_mng.prefetch_all()
324 p = None
325 for gindex, group in enumerate(self.param_groups):
326 for pindex, p in enumerate(group["params"]):
327 if p.grad is None:
328 continue
329 state = self.state[p]
330 if len(state) == 0:
331 self.init_state(group, p, gindex, pindex)
332
333 self.prefetch_state(p)
334 self.update_step(group, p, gindex, pindex)
335 sync_gpu(p)
336 if self.is_paged and p is not None:
337 # all paged operations are asynchronous, we need
338 # to sync to make sure all tensors are in the right state
339 sync_gpu(p)
340
341 return loss
342
343 def get_config(self, gindex, pindex, group):
344 config = {}

Callers

nothing calls this directly

Calls 6

check_overridesMethod · 0.95
to_gpuMethod · 0.95
init_stateMethod · 0.95
prefetch_stateMethod · 0.95
update_stepMethod · 0.95
sync_gpuFunction · 0.90

Tested by

no test coverage detected