Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep separate per-pipeline operator counters. Error out when "stealing" subgraphs from other pipelines results in duplicate names. #5506

Merged
merged 9 commits into from
Jun 11, 2024

Conversation

mzient
Copy link
Contributor

@mzient mzient commented Jun 6, 2024

Category:

New feature (non-breaking change which adds functionality)
Refactoring (Redesign of existing code that doesn't affect functionality)

Description:

Prior to this change constructing exactly the same pipeline (e.g. by calling a function decorated with @pipeline_def) multiple times produced pipelines with different operator instance names and differently named operator instances and DataNodes. This PR changes that so that pipelines with the same structure have the same node names.
This is achieved by:

  1. Using a separate operator counter in each pipeline. When all nodes all instantiated within pipeline scope, no further action is required. This happens for the vast majority of cases.
  2. If a name collision occurs (only possible when "stealing" a subgraph from another pipeline), an error is raised.

Pipelines that are defined without a "current" pipeline have distinct operator instance names.

Additionally, there were some problems with operator discovery. I rewrote it to a much simpler DFS.

Additional information:

Affected modules and functionalities:

Key points relevant for the review:

Tests:

pipeline_test.py: test_dangling_subgraph

  • Existing tests apply
  • New tests added
    • Python tests
    • GTests
    • Benchmark
    • Other
  • N/A

Checklist

Documentation

  • Existing documentation applies
  • Documentation updated
    • Docstring
    • Doxygen
    • RST
    • Jupyter
    • Other
  • N/A

DALI team only

Requirements

  • Implements new requirements
  • Affects existing requirements
  • N/A

REQ IDs: N/A

JIRA TASK: N/A

Comment on lines -2104 to -2134
def get_op_outputs_num():
# BSF traverse the graph first to learn, for each reachable operator in the graph,
# how many data-nodes/edges the operator contributes to
# (i.e. the number of outputs of the operator instance)
op_outputs_num = {}
edges = deque(output_nodes)
while edges:
current_edge = edges.popleft()
source_op = get_source_op(current_edge)
if source_op.id in op_outputs_num:
op_outputs_num[source_op.id] += 1
else:
op_outputs_num[source_op.id] = 1
source_op.check_args()
edges.extend(get_op_input_edges(source_op))
return op_outputs_num

visited = set()
ops = []
edges = deque(output_nodes)
op_total_outputs_num = get_op_outputs_num()
op_visited_outputs_num = {op_id: 0 for op_id in op_total_outputs_num}
while edges:
current_edge = edges.popleft()
source_op = get_source_op(current_edge)
op_visited_outputs_num[source_op.id] += 1
# Actually visit the operator only when all the nodes it contributes to
# were already processed
if op_visited_outputs_num[source_op.id] == op_total_outputs_num[source_op.id]:
ops.append(source_op)
edges.extend(get_op_input_edges(source_op))
ops.reverse()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was unnecessarily complex. DFS is much better suited for discovering topology.

@@ -57,7 +57,8 @@
class _OpCounter(object):
# pylint: disable=too-few-public-methods
_lock = threading.Lock()
_op_count = count(0)
# start from something large to avoid confusion with (more common) per-pipeline numbering
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for reviewers: "avoid confusion" means only confusion while debugging. The renaming can deal with duplicate names.

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [15624008]: BUILD STARTED

@szkarpinski szkarpinski self-assigned this Jun 6, 2024
@@ -57,7 +57,8 @@
class _OpCounter(object):
# pylint: disable=too-few-public-methods
_lock = threading.Lock()
_op_count = count(0)
# start from something large to avoid confusion with (more common) per-pipeline numbering
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# start from something large to avoid confusion with (more common) per-pipeline numbering
# start from something large to avoid confusion while debugging with (more common) per-pipeline numbering

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...

dali/python/nvidia/dali/pipeline.py Outdated Show resolved Hide resolved
dali/test/python/test_pipeline.py Outdated Show resolved Hide resolved
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [15624354]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [15624997]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [15624997]: BUILD FAILED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [15633718]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [15633718]: BUILD FAILED

@mzient mzient marked this pull request as draft June 7, 2024 06:53
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [15654084]: BUILD STARTED

dali/test/python/test_pipeline.py Fixed Show fixed Hide fixed
dali/test/python/test_pipeline.py Fixed Show fixed Hide fixed
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [15654084]: BUILD FAILED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [15654586]: BUILD STARTED

@NVIDIA NVIDIA deleted a comment from dali-automaton Jun 9, 2024
@mzient mzient marked this pull request as ready for review June 9, 2024 21:42
@mzient mzient changed the title Keep separate per-pipeline operator counters. Rename operator instances from other pipelines (including None). Keep separate per-pipeline operator counters. Error out when "stealing" subgraphs from other pipelines. Jun 9, 2024
@mzient mzient changed the title Keep separate per-pipeline operator counters. Error out when "stealing" subgraphs from other pipelines. Keep separate per-pipeline operator counters. Error out when "stealing" subgraphs from other pipelines results in duplicate names. Jun 9, 2024
@mzient mzient force-pushed the per_pipeline_name_generation branch from 6ac2b99 to a291562 Compare June 10, 2024 12:28
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [15709123]: BUILD FAILED

…es from other pipelines (including None).

Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
- handle renaming of duplicate nodes
- handle renaming of pipeline inputs that are not direct outputs of any operator
- improve error message

Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
…ends.

Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
@mzient mzient force-pushed the per_pipeline_name_generation branch from a291562 to 999c1cc Compare June 10, 2024 12:30
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [15734267]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [15734267]: BUILD PASSED

@mzient mzient merged commit 9dfdeac into NVIDIA:main Jun 11, 2024
6 checks passed
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants