MCPcopy Create free account
hub / github.com/pytorch/pytorch / BuildUniqueMutexIter

Function BuildUniqueMutexIter

caffe2/python/utils.py:341–375  ·  view source on GitHub ↗

Often, a mutex guarded iteration counter is needed. This function creates a mutex iter in the net uniquely (if the iter already existing, it does nothing) This function returns the iter blob

(
    init_net,
    net,
    iter=None,
    iter_mutex=None,
    iter_val=0
)

Source from the content-addressed store, hash-verified

339
340
341def BuildUniqueMutexIter(
342 init_net,
343 net,
344 iter=None,
345 iter_mutex=None,
346 iter_val=0
347):
348 '''
349 Often, a mutex guarded iteration counter is needed. This function creates a
350 mutex iter in the net uniquely (if the iter already existing, it does
351 nothing)
352
353 This function returns the iter blob
354 '''
355 iter = iter if iter is not None else OPTIMIZER_ITERATION_NAME
356 iter_mutex = iter_mutex if iter_mutex is not None else ITERATION_MUTEX_NAME
357 from caffe2.python import core
358 if not init_net.BlobIsDefined(iter):
359 # Add training operators.
360 with core.DeviceScope(
361 core.DeviceOption(caffe2_pb2.CPU,
362 extra_info=["device_type_override:cpu"])
363 ):
364 iteration = init_net.ConstantFill(
365 [],
366 iter,
367 shape=[1],
368 value=iter_val,
369 dtype=core.DataType.INT64,
370 )
371 iter_mutex = init_net.CreateMutex([], [iter_mutex])
372 net.AtomicIter([iter_mutex, iteration], [iteration])
373 else:
374 iteration = init_net.GetBlobRef(iter)
375 return iteration
376
377
378def EnumClassKeyVals(cls):

Callers

nothing calls this directly

Calls 2

BlobIsDefinedMethod · 0.80
GetBlobRefMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…