Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ticket
Problem description
What's changed
This PR adds support for the TopK operation (returning both values and indices) across the stack and also updates the graph builder and tensor utilities to better handle ops with multiple outputs. Core changes are mentioned below.
compile.py: Ensures a single IR op node per source op name and reuses it across multiple consumers/outputs and while creating tensors to build the graph, caches created op nodes by tensor.src_op.name and reuses them instead of creating duplicates and keeps output naming unique and stable so both TopK outputs can attach to the same underlying op node.
tvm_to_python.py: It Maps topk to forge and when consuming a TopK node’s indices (producer port 1), rewrites the input name to <topk_node_name>_indices and when a TopK node is a graph output, adds a secondary output name _indices so both values and indices are returned.
python_codegen.py: Modifies forgewriter to emit proper LHS unpacking for TopK and generates values, values_indices.
topk.py: Adds a Python-friendly layer and tuple-like wrapper for TopK. TensorPair wraps (values, indices) and behaves like a 2‑tuple, forwarding attributes to values and supporting set_src_layer for both. It computes golden outputs with torch.topk when input has values, otherwise creates correctly-shaped zero tensors and it creates Forge tensors from trace and sets their values and data formats to returns a TensorPair.
tensor.py: Extends conversion utilities to accept tuple-like wrappers (e.g., TensorPair) when converting to Forge tensors and detects iterable/sequence-like wrappers and flattens them into the corresponding list of Tensors.
The generated graph now unpacks two values from topk.


Logs
topk_pcc_correction.log