Repository navigation
Description
Status: reproducing witness confirmed (see comment). The earlier correction banner is obsolete. The defect reproduces deterministically on a four-collective graph; fix proposed in #124410.
Current behavior
CreateControlDependencies in tensorflow/core/graph/collective_order.cc serializes concurrent CollectiveReduce ops on a device. It creates a control edge for every pair that has no existing data path, oriented from the higher instance_key to the lower one (lines 99-106), then prunes them so that "if there are edges a -> b, b -> c, and a -> c, then remove a -> c" (lines 116-118).
That prune is a transitive reduction. The transitive reduction of a finite DAG is unique, so the correct output is fully determined by the input graph. The emitted set is neither that reduction nor a function of the input.
The reachability map is not a transitive closure
all_paths is documented at line 76 as "if there exists some path a -> ... -> b then all_paths[a] contains b". It is built at lines 107-111:
auto& src_paths = all_paths[src_node];
src_paths.insert(dst_node);
for (Node* downstream_node : all_paths[dst_node]) {
src_paths.insert(downstream_node);
}
all_paths[dst_node] is copied as it stands at the moment the edge src -> dst is created. When dst later acquires a successor, nothing propagates it back into src. all_paths therefore under-approximates reachability, on 2,737 of 7,290 enumerated configurations.
Two consequences
Redundant control edges survive. Because the prune tests membership in an incomplete all_paths, it fails to recognise paths of length three or more. The emitted set differs from the unique transitive reduction on 132 of 7,290 enumerated configurations.
The surviving edge set depends on heap addresses. The prune at lines 127-139 removes a neighbour by overwriting its slot with nullptr, and a neighbour already nulled is skipped as a pruner (if (n1 == nullptr) continue;). Which neighbours are nulled first is the iteration order of absl::flat_hash_set<Node*>, which is keyed by Node*. Under a complete closure that order is immaterial; under a partial one it changes the emitted set, not merely its presentation. For four collectives with a data path between instance keys 1 and 3, the prune emits either
{2->1, 3->2, 4->3} three edges
{2->1, 3->2, 4->1, 4->3} four edges
from one fixed input graph, selected by pointer values.
Reproducing witness
Four CollectiveReduce ops on one device, instance keys 1 to 4, with data paths between keys 1 and 3 and between keys 2 and 4. Four control edges are created: 2->1, 3->2, 4->3, 4->1. The path 4 -> 3 -> 2 -> 1 makes 4->1 redundant, so the unique transitive reduction is {2->1, 3->2, 4->3}.
all_paths[3] is populated from all_paths[2] when edge 3->2 is created, which precedes the creation of 2->1. Key 1 is never back-propagated into all_paths[3], the prune never sees 4 -> 3 -> 2 -> 1, and 4->1 is retained. On this witness every neighbour iteration order retains it, so the failure is deterministic rather than address-dependent.
The extra edge over-serializes the collectives: c1 waits on c4 directly in addition to the chain that already orders them.
Correctness of the intended output
Every edge runs from a higher instance key to a lower one, so instance keys strictly decrease along any path and ascending instance key is a reverse topological order. Closing reachability in that order requires a single pass, after which edge u -> v belongs to the reduction iff no other successor of u reaches v. Deciding each edge independently against the closed relation removes the nulling, and with it the dependence on container iteration order.
Feeding the prune an exact closure yields the unique transitive reduction on 819,324 (graph, neighbour-order) pairs enumerated over all permutations of 3 to 5 collectives crossed with all subsets of up to two data-path pairs and all neighbour orders.
Scratch
all_paths is an absl::flat_hash_map<Node*, absl::flat_hash_set<Node*>>, one 8-byte Node* slot plus a control byte per reachable pair at a 7/8 maximum load factor. A dense bit matrix over the same pairs costs one bit.
| collectives | reachable pairs | all_paths bytes |
bit matrix bytes | ratio |
|---|---|---|---|---|
| 64 | 2,016 | 20,736 | 512 | 40.5x |
| 256 | 32,640 | 335,725 | 8,192 | 41.0x |
| 1,024 | 523,776 | 5,387,410 | 131,072 | 41.1x |
Provenance
Read from tensorflow/tensorflow@491edf64e28. Counts come from an executable model of lines 71-143 enumerating all permutations of 3 to 5 collectives against all subsets of up to two data-path pairs; they are exact integers and machine-independent.
Related
VerifyAttrs in tensorflow/core/graph/collective_order_test.cc:68-70 skips nodes for which IsCollective() is true, while every key passed to it by SimpleOrderAttr and Pruning names a collective. Those wait_for assertions currently execute no comparisons. This is separate from the defect above and is not addressed here.
Limits
No wall-clock measurement is attached, and the scratch table is computed from the container's documented layout rather than from a heap profile of a running graph. The enumeration covers 3 to 5 collectives with at most two data-path pairs; larger configurations are covered by the argument above rather than by enumeration.
Activity
teerthsharma commentedon Jul 31, 2026
Correction: the reproducing witness does not reproduce
The "Reproducing witness" section above states that every neighbour iteration order retains the redundant edge
4->1, making the failure deterministic. Building that graph as acollective_order_testcase contradicts it. The test passes against the current implementation.Measurement
tensorflow/tensorflow@491edf64e28, built with GCC 15.2.0 and Bazel 7.7.0 on Ubuntu under WSL2, CPU configuration. The four-collective graph described above was added as a test case and//tensorflow/core/graph:collective_order_testwas run against the unpatched implementation: 5 of 5 cases pass, including the added one.The edge-creation order, recovered from the existing
VLOG(1)at line 103:2 -> 1is created before3 -> 2, soall_paths[3]is populated as{2, 1}and is complete at prune time. The prune sees the path4 -> 3 -> 2 -> 1and removes4 -> 1correctly.The witness was derived from a model that enumerated
collective_nodesorderings and assumed the ordering(2, 3, 1, 4). The orderingDiscoverDataDependenciesactually produces for this graph is[c2, c1, c4, c3]. The hole requires an edgeu -> vto be created before an edgev -> w; this ordering never does that.What the measurement leaves standing
all_pathsis still not the transitive closure its comment at line 76 claims. Lines 107-111 copyall_paths[dst]as it stands when the edgesrc -> dstis created, and no back-propagation exists, so a successor acquired bydstafterwards is never reflected insrc. That is a property of the code, independent of which orderings arise in practice.The prune at lines 127-139 still nulls a neighbour's slot and skips already-nulled neighbours as pruners, so its result is a function of
absl::flat_hash_set<Node*>iteration order whenever the closure is incomplete.What it retracts
The claim that a TensorFlow graph has been exhibited on which the incomplete closure changes the emitted control edges is withdrawn. No such graph is demonstrated here.
Whether the orderings
DiscoverDataDependenciescan produce are capable of opening the hole is open. The requirement is acollective_nodesordering placing the pair(v, w)earlier in the(i, j)enumeration than the pair(u, v)for some pathu -> v -> w. That is a constraint on the reverse-DFS output, not on the pruning code, and it is not settled by anything above.Status
Reported as a latent correctness and determinism defect rather than an observed miscompilation. Anyone reproducing should note that the counts quoted in the original report (2,737 of 7,290 and 132 of 7,290) come from enumerating
collective_nodesorderings directly, not from orderings observed on real graphs, and the gap between those two populations is exactly what this correction is about.teerthsharma commentedon Jul 31, 2026
Resolved: a reproducing witness exists
The previous comment withdrew the claim that a graph had been exhibited on which the incomplete closure changes the emitted control edges. That withdrawal is itself now superseded: such a graph exists, and the failure is deterministic.
Why the first attempt did not reproduce
A length-two alternate path can never expose the defect.
all_paths[v]receiveswat the moment the edgev -> wis created, sovis always able to prune a redundantu -> w. The failure requires a pathu -> v -> x -> win which the pair(v, x)reaches the(i, j)enumeration before the pair(x, w), leavingall_paths[v]fixed beforexacquiresw.The first graph assigned instance keys 1 to 4 in the order the collectives were constructed.
DiscoverDataDependenciesdiscovers them in the order[c2, c1, c4, c3], which produced the edge sequence2 -> 1,3 -> 2,4 -> 1,4 -> 3. There2 -> 1precedes3 -> 2, soall_paths[3]is complete and the prune is correct.The witness
The same graph shape, with the instance keys assigned so that they descend along the discovery order rather than the construction order. Four
CollectiveReduceops on one device, data paths between keys 3 and 1 and between 4 and 2. Edge creation order, from the existingVLOG(1)at line 103:all_paths[3]is fixed at{2}before2acquires1. The prune never sees4 -> 3 -> 2 -> 1, and4 -> 1survives. Emitted:against the unique transitive reduction
{4 -> 3, 3 -> 2, 2 -> 1}.Measurement
bazel test //tensorflow/core/graph:collective_order_test, GCC 15.2.0 and Bazel 7.7.0 on Ubuntu under WSL2, CPU configuration, from491edf64e28. Against the current implementation 4 of 5 cases pass and the added case fails, reporting four emitted edges where three are correct.SimpleOrder,SimpleOrderAttr,SimpleOrder2andPruningpass.The correction banner on the issue body is therefore obsolete and the original report stands, with one amendment: the counts quoted there (2,737 of 7,290 and 132 of 7,290) enumerate
collective_nodesorderings directly, and only a subset of those orderings is reachable throughDiscoverDataDependencies. The witness above is reachable.A fix is proposed in #124410.
Venkat6871 commentedon Aug 5, 2026
Hi @teerthsharma ,
Thank you for reporting this issue and for the fix.
This appears to have been resolved by PR #124410, which has now been merged into the main branch. Could you please verify whether the issue is resolved using the latest tf-nightly build? If everything looks good, this issue can be closed.
Thanks!
teerthsharma commentedon Aug 5, 2026
Yes it looks good closing issues will be perfect
google-ml-butler commentedon Aug 5, 2026
Are you satisfied with the resolution of your issue?
Yes
No