Skip to content

Commit

Permalink
inference -> evaluation, as requested
Browse files Browse the repository at this point in the history
Signed-off-by: Tomasz Kornuta <[email protected]>
  • Loading branch information
tkornuta-nvidia committed May 5, 2020
1 parent 327cc6d commit 831d269
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions nemo/backends/pytorch/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def __nm_graph_forward_pass(
# if module.is_trainable():
if isinstance(pmodule, nn.Module):
pmodule.train()
elif mode == OperationMode.inference:
elif mode == OperationMode.evaluation:
# if module.is_trainable():
if isinstance(pmodule, nn.Module):
pmodule.eval()
Expand Down Expand Up @@ -584,7 +584,7 @@ def _eval(self, tensors_2_evaluate, callback, step, verbose=False):
t.unique_name: d for t, d in zip(call_chain[0][2].values(), tensors) if t is not None
}
self.__nm_graph_forward_pass(
call_chain=call_chain, registered_tensors=registered_e_tensors, mode=OperationMode.inference,
call_chain=call_chain, registered_tensors=registered_e_tensors, mode=OperationMode.evaluation,
)

if not is_distributed or self.global_rank == 0:
Expand Down Expand Up @@ -766,7 +766,7 @@ def _infer(
self.__nm_graph_forward_pass(
call_chain=call_chain,
registered_tensors=registered_e_tensors,
mode=OperationMode.inference,
mode=OperationMode.evaluation,
use_cache=use_cache,
)

Expand Down
10 changes: 5 additions & 5 deletions nemo/core/neural_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ def __call__(self, **kwargs):
outer_mode = self._app_state.active_graph.operation_mode
inner_mode = self.operation_mode

if inner_mode == OperationMode.inference and outer_mode == OperationMode.training:
if inner_mode == OperationMode.evaluation and outer_mode == OperationMode.training:
raise TypeError("Cannot nest 'inference' graph into 'training'")

if inner_mode == OperationMode.training and outer_mode == OperationMode.inference:
if inner_mode == OperationMode.training and outer_mode == OperationMode.evaluation:
raise TypeError("Cannot nest 'training' graph into 'inference'")

if inner_mode == OperationMode.training and outer_mode == OperationMode.both:
raise TypeError("Cannot nest 'training' graph into 'both'")

if inner_mode == OperationMode.inference and outer_mode == OperationMode.both:
if inner_mode == OperationMode.evaluation and outer_mode == OperationMode.both:
raise TypeError("Cannot nest 'inference' graph into 'both'")

# Check inputs: iterate through all inputs passed to the "self".
Expand Down Expand Up @@ -525,7 +525,7 @@ def __serialize_header(self) -> Dict[str, Any]:
# Add operation mode.
if self._operation_mode == OperationMode.training:
header["operation_mode"] = "training"
elif self._operation_mode == OperationMode.inference:
elif self._operation_mode == OperationMode.evaluation:
header["operation_mode"] = "inference"
else:
header["operation_mode"] = "both"
Expand Down Expand Up @@ -717,7 +717,7 @@ def __deserialize_header(cls, serialized_header: Dict[str, Any]):
if serialized_header["operation_mode"] == "training":
operation_mode = OperationMode.training
elif serialized_header["operation_mode"] == "inference":
operation_mode = OperationMode.inference
operation_mode = OperationMode.evaluation
else:
operation_mode = OperationMode.both

Expand Down
12 changes: 6 additions & 6 deletions tests/unit/core/neural_graph/test_neural_graph_nesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def test_module_nesting1_change_operation_modes(self):
_, _ = dl()
assert dl.operation_mode == OperationMode.training

with NeuralGraph(operation_mode=OperationMode.inference):
with NeuralGraph(operation_mode=OperationMode.evaluation):
_, _ = dl()
assert dl.operation_mode == OperationMode.inference
assert dl.operation_mode == OperationMode.evaluation

@pytest.mark.unit
def test_graph_nesting2_possible_operation_modes(self):
Expand All @@ -63,7 +63,7 @@ def test_graph_nesting2_possible_operation_modes(self):
with NeuralGraph(operation_mode=OperationMode.training) as training:
_, _ = dl()

with NeuralGraph(operation_mode=OperationMode.inference) as inference:
with NeuralGraph(operation_mode=OperationMode.evaluation) as inference:
_, _ = dl()

# Allowed operations.
Expand All @@ -72,15 +72,15 @@ def test_graph_nesting2_possible_operation_modes(self):
_, _ = both()

# Can nest 'both' into 'inference'.
with NeuralGraph(operation_mode=OperationMode.inference):
with NeuralGraph(operation_mode=OperationMode.evaluation):
_, _ = both()

# Can nest 'training' into 'training'.
with NeuralGraph(operation_mode=OperationMode.training):
_, _ = training()

# Can nest 'inference' into 'inference'.
with NeuralGraph(operation_mode=OperationMode.inference):
with NeuralGraph(operation_mode=OperationMode.evaluation):
_, _ = inference()

# Can nest 'both' into 'both'.
Expand All @@ -95,7 +95,7 @@ def test_graph_nesting2_possible_operation_modes(self):

# Cannot nest 'training' into 'inference'.
with pytest.raises(TypeError):
with NeuralGraph(operation_mode=OperationMode.inference):
with NeuralGraph(operation_mode=OperationMode.evaluation):
_, _ = training()

# Cannot nest 'training' into 'both'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_graph_serialization_2_simple_graph_output_binding(self):
loss = MSELoss(name="tgs2_loss")

# Create the graph.
with NeuralGraph(operation_mode=OperationMode.inference) as g1:
with NeuralGraph(operation_mode=OperationMode.evaluation) as g1:
x, t = dl()
prediction1 = tn(x=x)
_ = loss(predictions=prediction1, target=t)
Expand Down

0 comments on commit 831d269

Please sign in to comment.