Skip to content

npu: the layer_types refusal is a substring test, so a linear-attention variant it cannot run is accepted as GDN #1156

Closed

Description

@bong-water-water-bong

The layer_types guard from #1124 refuses an unknown kind by name, but it decides "known" by substring:

npu/forward/src/q4nx_semantics.c:349-350

else if (strstr(nm, "sliding")) kind = Q4NX_LAYER_SLIDING;
else if (strstr(nm, "linear"))  kind = Q4NX_LAYER_LINEAR;

so the guarantee "refuse a layer kind this forward does not implement" is exactly as wide as the substring. A probe linking that same q4nx_semantics.c and parsing a two-entry layer_types (full_attention, <spelling>):

mamba2_linear              -> layer[1]=LINEAR(GDN) unknown=''
chunked_linear_attention   -> layer[1]=LINEAR(GDN) unknown=''
nonlinear_attention        -> layer[1]=LINEAR(GDN) unknown=''
conv_attention             -> layer[1]=OTHER       unknown='conv_attention'
linear_attention           -> layer[1]=LINEAR(GDN) unknown=''

Nothing in circulation hits this: every container on the box declares full_attention / linear_attention / sliding_attention, and linear_attention is the HF spelling the GDN path is for, so the family test is right today. The cost of being wrong later is the failure mode #1124 exists to remove: a spelling that contains "linear" but names an attention math the forward does not have would be served through the GDN recurrence, fluently and silently, instead of refused by name.

Suggested fix, one line plus one case: exact match against the known set (full_attention, linear_attention, sliding_attention, and any other spelling a real container uses) and let everything else fall to Q4NX_LAYER_OTHER, which the guard already refuses by name. tests/q4nx_layer_kinds_test.c case 2 would then also be the place to add chunked_linear_attention as a refused spelling.

Found while reviewing engine #1124 (the guard is a strict improvement over main, so that PR was not held for this).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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