Skip to content

Recover a tensor parameter's rank from a shape-constraining consumer operator (transpose permutation, einsum subscript) #734

Description

@khatchad

Summary

When a tensor parameter's incoming value has ⊤ shape (an unresolved-allocator-shape ReturnValueKey source, which the analysis self-labels a "Candidate for a #370 shape annotation"), a consumer operator inside the function frequently fixes the parameter's rank statically. Recovering the rank alone would turn a fully-⊤ shape into a rank-known, extents-⊤ shape, which is a materially stronger result: it pins rank plus dtype while leaving only the still-unresolved extents unknown. Note the "#370 candidate" tag does not by itself imply the shape is inherently content-dependent; it only records that the shape was not resolved, which spans both genuinely-dynamic extents and statically-recoverable structure the analysis is currently missing (e.g. a fixed label-count trailing dimension).

Observed (NLPGNN, 0.52.31)

Transpose permutation length. nlpgnn/metrics/crf.py's crf_forward(inputs, state, ...) begins inputs = tf.transpose(inputs, [1, 0, 2]), so inputs is provably rank-3. Six crf.py parameters (the unary potentials and the recurrence state across crf_forward, crf_unary_score, crf_log_norm, crf_sequence_score, CrfLogLikelihood.call) infer a concrete float32 dtype but a fully-⊤ shape.

Einsum subscript. DenseLayer3dProj.call's tf.einsum("BFND,NDH->BFH", input_tensor, w) fixes input_tensor at rank-4 and shares the N/D labels with the statically-shaped w. Tracked as its own instance in #704.

Relationship To Existing Issues

Why It Matters

Rank plus dtype is what distinguishes a retracing-reducing shape from a fully-open one, so recovering rank on these content-dependent tensors is the highest-leverage precision step short of user annotations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions