/usr/local/lib64/python3.6/site-packages/caffe2/python
NameSizeModeActions
docs/-0755rm
examples/-0755rm
fakelowp/-0755rm
helpers/-0755rm
ideep/-0755rm
layers/-0755rm
mint/-0755rm
mkl/-0755rm
modeling/-0755rm
models/-0755rm
onnx/-0755rm
operator_test/-0755rm
predictor/-0755rm
rnn/-0755rm
serialized_test/-0755rm
test/-0755rm
trt/-0755rm
__pycache__/-0755rm
allcompare_test.py22550644editdlrm
attention.py123590644editdlrm
benchmark_generator.py49120644editdlrm
binarysize.py55210644editdlrm
brew.py47620644editdlrm
brew_test.py117390644editdlrm
build.py1530644editdlrm
cached_reader.py43940644editdlrm
caffe2_pybind11_state.cpython-36m-x86_64-linux-gnu.so482997120755editdlrm
caffe2_pybind11_state_gpu.cpython-36m-x86_64-linux-gnu.so490481440755editdlrm
caffe_translator.py352270644editdlrm
caffe_translator_test.py35530644editdlrm
checkpoint.py321010644editdlrm
checkpoint_test.py134050644editdlrm
cnn.py76260644editdlrm
context.py28410644editdlrm
context_test.py17920644editdlrm
control.py193090644editdlrm
control_ops_grad.py288930644editdlrm
control_ops_grad_test.py17520644editdlrm
control_ops_util.py108630644editdlrm
control_test.py122760644editdlrm
convert.py550644editdlrm
convert_test.py2010644editdlrm
convnet_benchmarks.py205330644editdlrm
convnet_benchmarks_test.py8390644editdlrm
core.py1194000644editdlrm
core_gradients_test.py380220644editdlrm
core_test.py476830644editdlrm
crf.py132500644editdlrm
crf_predict.py11590644editdlrm
crf_viterbi_test.py16630644editdlrm
dataio.py235320644editdlrm
dataio_test.py175750644editdlrm
dataset.py128860644editdlrm
data_parallel_model.py831000644editdlrm
data_parallel_model_test.py561450644editdlrm
data_workers.py159410644editdlrm
data_workers_test.py65610644editdlrm
db_file_reader.py66080644editdlrm
db_test.py11100644editdlrm
device_checker.py51570644editdlrm
dyndep.py15330644editdlrm
embedding_generation_benchmark.py52560644editdlrm
experiment_util.py36250644editdlrm
extension_loader.py7440644editdlrm
fakefp16_transform_lib.py3220644editdlrm
filler_test.py7480644editdlrm
functional.py44150644editdlrm
functional_test.py42040644editdlrm
fused_8bit_rowwise_conversion_ops_test.py39450644editdlrm
gradient_checker.py153770644editdlrm
gradient_check_test.py207290644editdlrm
gru_cell.py51290644editdlrm
hip_test_util.py4050644editdlrm
hsm_util.py22590644editdlrm
hypothesis_test.py1057620644editdlrm
hypothesis_test_util.py268530644editdlrm
ideep_test_util.py9980644editdlrm
layers_test.py929310644editdlrm
layer_model_helper.py293400644editdlrm
layer_model_instantiator.py39350644editdlrm
layer_parameter_sharing_test.py91480644editdlrm
layer_test_util.py48750644editdlrm
lazy.py2770644editdlrm
lazy_dyndep.py25620644editdlrm
lazy_dyndep_test.py39140644editdlrm
lengths_reducer_fused_8bit_rowwise_ops_test.py75750644editdlrm
lengths_reducer_rowwise_8bit_ops_test.py57100644editdlrm
lstm_benchmark.py106490644editdlrm
memonger.py340410644editdlrm
memonger_test.py369100644editdlrm
mkl_test_util.py11420644editdlrm
model_device_test.py47770644editdlrm
model_helper.py234920644editdlrm
model_helper_test.py23360644editdlrm
modifier_context.py17720644editdlrm
muji.py81310644editdlrm
muji_test.py30580644editdlrm
net_builder.py276790644editdlrm
net_builder_test.py113820644editdlrm
net_drawer.py142640644editdlrm
net_printer.py127040644editdlrm
net_printer_test.py31900644editdlrm
nomnigraph.py42160644editdlrm
nomnigraph_test.py154270644editdlrm
nomnigraph_transformations.py37870644editdlrm
nomnigraph_transformations_test.py57670644editdlrm
normalizer.py14110644editdlrm
normalizer_context.py10070644editdlrm
normalizer_test.py4870644editdlrm
numa_benchmark.py22300644editdlrm
numa_test.py16630644editdlrm
observer_test.py53160644editdlrm
operator_fp_exceptions_test.py12480644editdlrm
optimizer.py788130644editdlrm
optimizer_context.py14620644editdlrm
optimizer_test.py307050644editdlrm
optimizer_test_util.py91870644editdlrm
parallelize_bmuf_distributed_test.py99080644editdlrm
parallel_workers.py76820644editdlrm
parallel_workers_test.py35010644editdlrm
pipeline.py172830644editdlrm
pipeline_test.py25420644editdlrm
predictor_constants.py1980644editdlrm
python_op_test.py91690644editdlrm
queue_util.py44590644editdlrm
record_queue.py44530644editdlrm
recurrent.py132970644editdlrm
regularizer.py211200644editdlrm
regularizer_context.py10130644editdlrm
regularizer_test.py102660644editdlrm
rnn_cell.py682330644editdlrm
schema.py456210644editdlrm
schema_test.py157540644editdlrm
scope.py36230644editdlrm
scope_test.py52490644editdlrm
session.py76420644editdlrm
session_test.py20780644editdlrm
sparse_to_dense_mask_test.py65650644editdlrm
sparse_to_dense_test.py35560644editdlrm
task.py242740644editdlrm
task_test.py8700644editdlrm
test_util.py35240644editdlrm
text_file_reader.py19900644editdlrm
timeout_guard.py40540644editdlrm
toy_regression_test.py28220644editdlrm
transformations.py18320644editdlrm
transformations_test.py119600644editdlrm
tt_core.py93490644editdlrm
tt_core_test.py25180644editdlrm
utils.py141810644editdlrm
utils_test.py13990644editdlrm
visualize.py63150644editdlrm
workspace.py252630644editdlrm
workspace_test.py348440644editdlrm
_import_c_extension.py22500644editdlrm
__init__.py39250644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/caffe2/python/net_builder_test.py (11382B)
from caffe2.python import workspace from caffe2.python.core import Plan, to_execution_step, Net from caffe2.python.task import Task, TaskGroup, final_output from caffe2.python.net_builder import ops, NetBuilder from caffe2.python.session import LocalSession import unittest import threading class PythonOpStats(object): lock = threading.Lock() num_instances = 0 num_calls = 0 def python_op_builder(): PythonOpStats.lock.acquire() PythonOpStats.num_instances += 1 PythonOpStats.lock.release() def my_op(inputs, outputs): PythonOpStats.lock.acquire() PythonOpStats.num_calls += 1 PythonOpStats.lock.release() return my_op def _test_loop(): x = ops.Const(5) y = ops.Const(0) with ops.loop(): ops.stop_if(ops.EQ([x, ops.Const(0)])) ops.Add([x, ops.Const(-1)], [x]) ops.Add([y, ops.Const(1)], [y]) return y def _test_inner_stop(x): ops.stop_if(ops.LT([x, ops.Const(5)])) def _test_outer(): x = ops.Const(10) # test stop_if(False) with ops.stop_guard() as g1: _test_inner_stop(x) # test stop_if(True) y = ops.Const(3) with ops.stop_guard() as g2: _test_inner_stop(y) # test no stop with ops.stop_guard() as g4: ops.Const(0) # test empty clause with ops.stop_guard() as g3: pass return ( g1.has_stopped(), g2.has_stopped(), g3.has_stopped(), g4.has_stopped()) def _test_if(x): y = ops.Const(1) with ops.If(ops.GT([x, ops.Const(50)])): ops.Const(2, blob_out=y) with ops.If(ops.LT([x, ops.Const(50)])): ops.Const(3, blob_out=y) ops.stop() ops.Const(4, blob_out=y) return y class TestNetBuilder(unittest.TestCase): def test_ops(self): with NetBuilder() as nb: y = _test_loop() z, w, a, b = _test_outer() p = _test_if(ops.Const(75)) q = _test_if(ops.Const(25)) plan = Plan('name') plan.AddStep(to_execution_step(nb)) ws = workspace.C.Workspace() ws.run(plan) expected = [ (y, 5), (z, False), (w, True), (a, False), (b, False), (p, 2), (q, 3), ] for b, expected in expected: actual = ws.blobs[str(b)].fetch() self.assertEquals(actual, expected) def _expected_loop(self): total = 0 total_large = 0 total_small = 0 total_tiny = 0 for loop_iter in range(10): outer = loop_iter * 10 for inner_iter in range(loop_iter): val = outer + inner_iter if val >= 80: total_large += val elif val >= 50: total_small += val else: total_tiny += val total += val return total, total_large, total_small, total_tiny def _actual_loop(self): total = ops.Const(0) total_large = ops.Const(0) total_small = ops.Const(0) total_tiny = ops.Const(0) with ops.loop(10) as loop: outer = ops.Mul([loop.iter(), ops.Const(10)]) with ops.loop(loop.iter()) as inner: val = ops.Add([outer, inner.iter()]) with ops.If(ops.GE([val, ops.Const(80)])) as c: ops.Add([total_large, val], [total_large]) with c.Elif(ops.GE([val, ops.Const(50)])) as c: ops.Add([total_small, val], [total_small]) with c.Else(): ops.Add([total_tiny, val], [total_tiny]) ops.Add([total, val], total) return [ final_output(x) for x in [total, total_large, total_small, total_tiny] ] def test_net_multi_use(self): with Task() as task: total = ops.Const(0) net = Net('my_net') net.Add([total, net.Const(1)], [total]) ops.net(net) ops.net(net) result = final_output(total) with LocalSession() as session: session.run(task) self.assertEquals(2, result.fetch()) def test_loops(self): with Task() as task: out_actual = self._actual_loop() with LocalSession() as session: session.run(task) expected = self._expected_loop() actual = [o.fetch() for o in out_actual] for e, a in zip(expected, actual): self.assertEquals(e, a) def test_setup(self): with Task() as task: with ops.task_init(): one = ops.Const(1) two = ops.Add([one, one]) with ops.task_init(): three = ops.Const(3) accum = ops.Add([two, three]) # here, accum should be 5 with ops.task_exit(): # here, accum should be 6, since this executes after lines below seven_1 = ops.Add([accum, one]) six = ops.Add([accum, one]) ops.Add([accum, one], [accum]) seven_2 = ops.Add([accum, one]) o6 = final_output(six) o7_1 = final_output(seven_1) o7_2 = final_output(seven_2) with LocalSession() as session: session.run(task) self.assertEquals(o6.fetch(), 6) self.assertEquals(o7_1.fetch(), 7) self.assertEquals(o7_2.fetch(), 7) def test_multi_instance_python_op(self): """ When task instances are created at runtime, C++ concurrently creates multiple instances of operators in C++, and concurrently destroys them once the task is finished. This means that the destructor of PythonOp will be called concurrently, so the GIL must be acquired. This test exercises this condition. """ with Task(num_instances=64) as task: with ops.loop(4): ops.Python((python_op_builder, [], {}))([], []) with LocalSession() as session: PythonOpStats.num_instances = 0 PythonOpStats.num_calls = 0 session.run(task) self.assertEquals(PythonOpStats.num_instances, 64) self.assertEquals(PythonOpStats.num_calls, 256) def test_multi_instance(self): NUM_INSTANCES = 10 NUM_ITERS = 15 with TaskGroup() as tg: with Task(num_instances=NUM_INSTANCES): with ops.task_init(): counter1 = ops.CreateCounter([], ['global_counter']) counter2 = ops.CreateCounter([], ['global_counter2']) counter3 = ops.CreateCounter([], ['global_counter3']) # both task_counter and local_counter should be thread local with ops.task_instance_init(): task_counter = ops.CreateCounter([], ['task_counter']) local_counter = ops.CreateCounter([], ['local_counter']) with ops.loop(NUM_ITERS): ops.CountUp(counter1) ops.CountUp(task_counter) ops.CountUp(local_counter) # gather sum of squares of local counters to make sure that # each local counter counted exactly up to NUM_ITERS, and # that there was no false sharing of counter instances. with ops.task_instance_exit(): count2 = ops.RetrieveCount(task_counter) with ops.loop(ops.Mul([count2, count2])): ops.CountUp(counter2) # This should have the same effect as the above count3 = ops.RetrieveCount(local_counter) with ops.loop(ops.Mul([count3, count3])): ops.CountUp(counter3) # The code below will only run once with ops.task_exit(): total1 = final_output(ops.RetrieveCount(counter1)) total2 = final_output(ops.RetrieveCount(counter2)) total3 = final_output(ops.RetrieveCount(counter3)) with LocalSession() as session: session.run(tg) self.assertEquals(total1.fetch(), NUM_INSTANCES * NUM_ITERS) self.assertEquals(total2.fetch(), NUM_INSTANCES * (NUM_ITERS ** 2)) self.assertEquals(total3.fetch(), NUM_INSTANCES * (NUM_ITERS ** 2)) def test_if_net(self): with NetBuilder() as nb: x0 = ops.Const(0) x1 = ops.Const(1) x2 = ops.Const(2) y0 = ops.Const(0) y1 = ops.Const(1) y2 = ops.Const(2) # basic logic first_res = ops.Const(0) with ops.IfNet(ops.Const(True)): ops.Const(1, blob_out=first_res) with ops.Else(): ops.Const(2, blob_out=first_res) second_res = ops.Const(0) with ops.IfNet(ops.Const(False)): ops.Const(1, blob_out=second_res) with ops.Else(): ops.Const(2, blob_out=second_res) # nested and sequential ifs, # empty then/else, # passing outer blobs into branches, # writing into outer blobs, incl. into input blob # using local blobs with ops.IfNet(ops.LT([x0, x1])): local_blob = ops.Const(900) ops.Add([ops.Const(100), local_blob], [y0]) gt = ops.GT([x1, x2]) with ops.IfNet(gt): # empty then pass with ops.Else(): ops.Add([y1, local_blob], [local_blob]) ops.Add([ops.Const(100), y1], [y1]) with ops.IfNet(ops.EQ([local_blob, ops.Const(901)])): ops.Const(7, blob_out=y2) ops.Add([y1, y2], [y2]) with ops.Else(): # empty else pass plan = Plan('if_net_test') plan.AddStep(to_execution_step(nb)) ws = workspace.C.Workspace() ws.run(plan) first_res_value = ws.blobs[str(first_res)].fetch() second_res_value = ws.blobs[str(second_res)].fetch() y0_value = ws.blobs[str(y0)].fetch() y1_value = ws.blobs[str(y1)].fetch() y2_value = ws.blobs[str(y2)].fetch() self.assertEquals(first_res_value, 1) self.assertEquals(second_res_value, 2) self.assertEquals(y0_value, 1000) self.assertEquals(y1_value, 101) self.assertEquals(y2_value, 108) self.assertTrue(str(local_blob) not in ws.blobs) def test_while_net(self): with NetBuilder() as nb: x = ops.Const(0) y = ops.Const(0) with ops.WhileNet(): with ops.Condition(): ops.Add([x, ops.Const(1)], [x]) ops.LT([x, ops.Const(7)]) ops.Add([x, y], [y]) plan = Plan('while_net_test') plan.AddStep(to_execution_step(nb)) ws = workspace.C.Workspace() ws.run(plan) x_value = ws.blobs[str(x)].fetch() y_value = ws.blobs[str(y)].fetch() self.assertEqual(x_value, 7) self.assertEqual(y_value, 21)