Ejemplo n.º 1
0
    def test_estimator_sort_traces_with_available_outputs_have_no_dependency(
            self):
        trace1 = Trace(inputs="x", outputs="y")
        trace2 = Trace(inputs="x", outputs="z")
        trace3 = Trace(inputs="x", outputs="x")

        with self.subTest("[trace1, trace2]"):
            sorted_traces = fe.trace.sort_traces([trace1, trace2],
                                                 available_outputs="x")
            self.assertEqual(sorted_traces, [trace1, trace2])

        with self.subTest("[trace2, trace1]"):
            sorted_traces = fe.trace.sort_traces([trace2, trace1],
                                                 available_outputs="x")
            self.assertEqual(sorted_traces, [trace2, trace1])

        with self.subTest("[trace1, trace3]"):
            sorted_traces = fe.trace.sort_traces([trace1, trace3],
                                                 available_outputs="x")
            self.assertEqual(sorted_traces, [trace1, trace3])

        with self.subTest("[trace3, trace1]"):
            sorted_traces = fe.trace.sort_traces([trace3, trace1],
                                                 available_outputs="x")
            self.assertEqual(sorted_traces, [trace3, trace1])
Ejemplo n.º 2
0
    def test_estimator_sort_traces_without_available_outputs_have_dependency(
            self):
        trace1 = Trace(inputs="x", outputs="y")
        trace2 = Trace(inputs="y", outputs="z")
        trace3 = Trace(inputs="z", outputs="w")

        sorted_traces = fe.trace.sort_traces([trace3, trace2, trace1])
        self.assertEqual(sorted_traces, [trace1, trace2, trace3])
Ejemplo n.º 3
0
    def test_estimator_sort_traces_cycle_dependency(self):
        trace1 = Trace(inputs="x", outputs="y")
        trace2 = Trace(inputs="y", outputs="z")
        trace3 = Trace(inputs="z", outputs="x")
        trace4 = Trace(inputs="x", outputs="a")

        with self.subTest("available_outputs='x'"):
            sorted_traces = fe.trace.sort_traces(
                [trace1, trace2, trace3, trace4], available_outputs="y")
            self.assertEqual(sorted_traces, [trace2, trace3, trace4, trace1])

        with self.subTest("available_output=None"):
            with self.assertRaises(AssertionError):
                sorted_traces = fe.trace.sort_traces(
                    [trace1, trace2, trace3, trace4])
Ejemplo n.º 4
0
 def test_estimator_warmup_tf_dataset_torch_model_smoke(self):
     loader = get_sample_tf_dataset(expand_axis=1)
     pipeline = fe.Pipeline(train_data=loader)  # "x", "y"
     model = fe.build(model_fn=LeNetTorch, optimizer_fn="adam")
     network = fe.Network(ops=[ModelOp(model=model, inputs="x", outputs="y_pred")])
     est = fe.Estimator(pipeline=pipeline, network=network, epochs=1, traces=[Trace(inputs="y_pred")])
     est._prepare_traces(run_modes={"train", "eval"})
     est._warmup()
     self.assertTrue(True)
Ejemplo n.º 5
0
    def test_estimator_warmup_trace_missing_key(self):
        loader = get_sample_tf_dataset()
        pipeline = fe.Pipeline(train_data=loader)  # "x", "y"
        model = fe.build(model_fn=LeNetTf, optimizer_fn="adam")

        network = fe.Network(
            ops=[ModelOp(model=model, inputs="x", outputs="y_pred")])

        est = fe.Estimator(pipeline=pipeline,
                           network=network,
                           epochs=1,
                           traces=[Trace(inputs="z")])  # miss key "z"
        est._prepare_traces(run_modes={"train", "eval"})
        with self.assertRaises(AssertionError):
            est._warmup(warmup=True)
Ejemplo n.º 6
0
 def test_estimator_sort_traces_with_available_outputs_no_input_match(self):
     trace1 = Trace(inputs="y", outputs="z")
     with self.assertRaises(AssertionError):
         sorted_traces = fe.trace.sort_traces([trace1],
                                              available_outputs="x")