/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/python_op_test.py (9169B)
from caffe2.python import core, workspace from caffe2.python.core import CreatePythonOperator import caffe2.python.hypothesis_test_util as hu from hypothesis import given, settings import hypothesis.strategies as st import numpy as np class CustomError(Exception): pass def SubFunctionThatThrowsCustomError(): raise CustomError("This is an intentional exception.") def MainOpFunctionThatThrowsCustomError(inputs, _): return SubFunctionThatThrowsCustomError() def MainOpFunctionThatThrowsCustomErrorInBuilder(inputs, _): raise CustomError("This is an intentional exception in builder.") def op_builder(name, index, extra): iterations = [0] assert name == 'name' assert index == 5 assert extra - 4.2 < 0.0001 def my_op(inputs, outputs): assert inputs[0].data[0] == iterations[0] assert name == 'name' assert index == 5 assert extra - 4.2 < 0.0001 iterations[0] += 1 return my_op class PythonOpTest(hu.HypothesisTestCase): @given(x=hu.tensor()) def test_feed(self, x): def f(inputs, _): self.assertEqual(x.shape, inputs[0].shape) self.assertEqual(type(inputs[0].shape), tuple) self.assertEqual(type(inputs[0].data), np.ndarray) np.testing.assert_almost_equal(x, inputs[0].data) op = CreatePythonOperator(f, ["x"], []) workspace.FeedBlob("x", x) workspace.RunOperatorOnce(op) def test_exception(self): op = CreatePythonOperator(MainOpFunctionThatThrowsCustomError, [], []) with self.assertRaisesRegex(CustomError, "This is an intentional exception."): workspace.RunOperatorOnce(op) def test_exception_builder(self): op = CreatePythonOperator(MainOpFunctionThatThrowsCustomErrorInBuilder, [], []) with self.assertRaisesRegex(CustomError, "This is an intentional exception in builder."): workspace.RunOperatorOnce(op) @given(x=hu.tensor()) def test_feed_with_helper_function(self, x): def f(inputs, _): self.assertEqual(x.shape, inputs[0].shape) self.assertEqual(type(inputs[0].shape), tuple) self.assertEqual(type(inputs[0].data), np.ndarray) np.testing.assert_almost_equal(x, inputs[0].data) net = core.Net("test") net.Python(f)(["x"], []) workspace.FeedBlob("x", x) workspace.RunNetOnce(net) def test_builder_tuple(self): net = core.Net("builder_template") iter_blob = 'iter' net.Python((op_builder, ['name', 5], {'extra': 4.2}))([iter_blob], []) net.Python((op_builder, ['name', 5], {'extra': 4.2}))([iter_blob], []) for repeat in range(2): # check that the builder will be called exactly once for each # PythonOp constructor. Cloning the net will also trigger a call # to the builder when the net is created. cloned_net = net.Clone('builder_%d' % repeat) workspace.FeedBlob(iter_blob, np.array([0])) # Builder gets called once per python op in the line below workspace.CreateNet(cloned_net) for i in range(10): workspace.FeedBlob(iter_blob, np.array([i])) workspace.RunNet(cloned_net) @given(x=hu.tensor()) def test_feed_with_gc(self, x): def f(inputs, _): self.assertEqual(x.shape, inputs[0].shape) np.testing.assert_almost_equal(x, inputs[0].data) op = CreatePythonOperator(f, ["x"], []) workspace.FeedBlob("x", x) workspace.RunOperatorOnce(op) del f workspace.FeedBlob("x", x) workspace.RunOperatorOnce(op) @given(x=hu.tensor()) def test_reshape(self, x): def f(inputs, outputs): outputs[0].reshape(inputs[0].shape) self.assertEqual(x.shape, inputs[0].shape) self.assertEqual(x.shape, outputs[0].shape) outputs[0].data[...] = inputs[0].data op = CreatePythonOperator(f, ["x"], ["y"]) workspace.FeedBlob("x", x) workspace.RunOperatorOnce(op) y = workspace.FetchBlob("y") np.testing.assert_almost_equal(x, y) @given(x=hu.tensor()) def test_workspace_manipulation(self, x): """ Verify that python op can manipulate workspace directly """ def f(inputs, outputs, ws): fetched = ws.blobs['internal'].fetch() np.testing.assert_almost_equal(fetched, x) ws = workspace.C.Workspace() net = core.Net("test") net.GivenTensorFill([], ['internal'], values=x, shape=x.shape) net.Python(f, pass_workspace=True)([], []) ws.run(net) @given(x=hu.tensor()) def test_caught_exception_doesnt_terminate(self, x): def f(inputs, outputs): try: raise Exception("Exception in handler") except Exception: pass op = CreatePythonOperator(f, ["x"], ["y"]) workspace.FeedBlob("x", x) workspace.RunOperatorOnce(op) @given(x=hu.tensor(), n=st.integers(min_value=1, max_value=20), w=st.integers(min_value=1, max_value=20)) @settings(deadline=1000) def test_multithreaded_evaluation(self, x, n, w): def f(inputs, outputs): outputs[0].reshape(inputs[0].shape) outputs[0].data[...] = inputs[0].data ops = [CreatePythonOperator(f, ["x"], [str(i)]) for i in range(n)] net = core.Net("net") net.Proto().op.extend(ops) net.Proto().type = "dag" net.Proto().num_workers = w iters = 100 plan = core.Plan("plan") plan.AddStep(core.ExecutionStep("test-step", net, iters)) workspace.FeedBlob("x", x) workspace.RunPlan(plan.Proto().SerializeToString()) for i in range(n): y = workspace.FetchBlob(str(i)) np.testing.assert_almost_equal(x, y) @given(x=hu.tensor(), in_place=st.booleans(), **hu.gcs) @settings(deadline=10000) def test_gradient(self, x, in_place, gc, dc): def f(inputs, outputs): outputs[0].reshape(inputs[0].shape) outputs[0].data[...] = inputs[0].data * 2 def grad_f(inputs, outputs): # Ordering is [inputs, outputs, grad_outputs] grad_output = inputs[2] grad_input = outputs[0] grad_input.reshape(grad_output.shape) grad_input.data[...] = grad_output.data * 2 op = CreatePythonOperator( f, ["x"], ["x" if in_place else "y"], grad_f=grad_f) self.assertGradientChecks(gc, op, [x], 0, [0]) self.assertDeviceChecks(dc, op, [x], [0]) @given(inputs=hu.tensors(n=2), **hu.gcs) @settings(deadline=10000) def test_gradient_multiple(self, inputs, gc, dc): (x1, x2) = inputs def f(inputs, outputs): for idx in [0, 1]: self.assertEqual(type(inputs[idx].shape), tuple) outputs[idx].reshape(inputs[idx].shape) outputs[idx].data[...] = inputs[idx].data * 2 def grad_f(inputs, outputs): # Ordering is [inputs, outputs, grad_outputs] self.assertEqual(len(inputs), 6) self.assertEqual(len(outputs), 2) for (grad_output_idx, grad_input_idx) in [(4, 0), (5, 1)]: grad_output = inputs[grad_output_idx] grad_input = outputs[grad_input_idx] grad_input.reshape(grad_output.shape) grad_input.data[...] = grad_output.data * 2 op = CreatePythonOperator(f, ["x1", "x2"], ["y1", "y2"], grad_f=grad_f) for idx in [0, 1]: self.assertGradientChecks(gc, op, [x1, x2], idx, [0, 1]) self.assertDeviceChecks(dc, op, [x1, x2], [0, 1]) @given(inputs=hu.tensors(n=3), **hu.gcs) @settings(deadline=10000) def test_gradient_multiple_with_indices(self, inputs, gc, dc): (x1, x2, x3) = inputs def f(inputs, outputs): for idx in [0, 1, 2]: self.assertEqual(type(inputs[idx].shape), tuple) outputs[idx].reshape(inputs[idx].shape) outputs[idx].data[...] = inputs[idx].data * 2 def grad_f(inputs, outputs): # Ordering is [inputs, outputs, grad_outputs] self.assertEqual(len(inputs), 8) self.assertEqual(len(outputs), 1) for (grad_output_idx, grad_input_idx) in [(6, 0)]: grad_output = inputs[grad_output_idx] grad_input = outputs[grad_input_idx] grad_input.reshape(grad_output.shape) grad_input.data[...] = grad_output.data * 2 op = CreatePythonOperator( f, ["x1", "x2", "x3"], ["y1", "y2", "y3"], grad_f=grad_f, grad_output_indices=[0, 2], # Receive grad outputs for y1 and y3 grad_input_indices=[0] # Produce grad inputs for x1 ) self.assertGradientChecks(gc, op, [x1, x2, x3], 0, [0, 2]) self.assertDeviceChecks(dc, op, [x1, x2, x3], [0, 1, 2])