Skip to content

Token-mask helpers infer unknown rank where the body requires rank 2 #810

Description

@khatchad

Two gpt-2 helpers are inferred with unknown rank while their bodies determine the rank exactly.

  • get_padding_mask(seq) slices seq[:, tf.newaxis, tf.newaxis, :], which is well-formed only for a rank-2 argument.
  • create_masks(inp) indexes tf.shape(inp)[1] and forwards inp to get_padding_mask, so it inherits the same requirement.

Both are inferred as unknown-rank rather than as a rank-2 tensor with two variable axes. The axes themselves are correctly variable, since the sole call site passes the pipeline token tensor whose batch and sequence lengths both vary, so the recovery wanted here is the rank, not the extents.

Rank is derivable from the body in both cases: an extended slice with two tf.newaxis insertions and two positional slices constrains the operand rank directly, and a tf.shape(x)[1] read establishes a lower bound. Recovering it would move these parameters from an unknown-rank spec to a rank-2 spec with two required wildcards, which is a strictly better signature.

The call sites and line numbers behind each axis are recorded alongside the analysis notes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions