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
)
| 339 | |
| 340 | |
| 341 | def 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 | |
| 378 | def EnumClassKeyVals(cls): |
nothing calls this directly
no test coverage detected
searching dependent graphs…