mirror of
https://github.com/saymrwulf/pytorch.git
synced 2026-05-15 21:00:47 +00:00
Summary: - Key-value store for counters. - Counters are updated via macros that also export USTD probes. - Counter values can be exported using caffe2 operators. - Snapshot mechanism for tracking time-window counter values. Reviewed By: dzhulgakov, pietern Differential Revision: D4553761 fbshipit-source-id: 25a1a91a3168dcff2159c6fba7b357d3fd3aa9bf
30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
from __future__ import absolute_import
|
|
from __future__ import division
|
|
from __future__ import print_function
|
|
from __future__ import unicode_literals
|
|
|
|
from caffe2.python import core, workspace
|
|
from caffe2.python.test_util import TestCase
|
|
import numpy as np
|
|
|
|
|
|
class TestCounterOps(TestCase):
|
|
|
|
def test_stats_ops(self):
|
|
workspace.FeedBlob('k', np.array(['k0', 'k1'], dtype=str))
|
|
workspace.FeedBlob('v', np.array([34, 45], dtype=np.int64))
|
|
for _ in range(2):
|
|
workspace.RunOperatorOnce(core.CreateOperator(
|
|
'StatRegistryUpdate', ['k', 'v'], []))
|
|
workspace.RunOperatorOnce(core.CreateOperator(
|
|
'StatRegistryExport', [], ['k2', 'v2', 'ts']))
|
|
|
|
workspace.RunOperatorOnce(core.CreateOperator(
|
|
'StatRegistryCreate', [], ['reg']))
|
|
workspace.RunOperatorOnce(core.CreateOperator(
|
|
'StatRegistryUpdate', ['k2', 'v2', 'reg'], []))
|
|
|
|
workspace.RunOperatorOnce(core.CreateOperator(
|
|
'StatRegistryExport', ['reg'], ['k3', 'v3', 'ts']))
|
|
self.assertTrue(len(workspace.FetchBlob('k3')) == 2)
|
|
self.assertTrue(len(workspace.FetchBlob('v3')) == 2)
|