                            Large Language Models Can Perform Tasks Without Instruction via Selective Attention Head Masking

               0                                                                                                That          # of removed    Generated outputs

                                                                                                                It                       0    That’s quite a surprise! Llamas are not typically found in backyards, so it’s

                                                                                                                L

             500                                                                                                I

                                                                                                                                         1    That’s quite a surprise! Llamas are not typically found in backyards, so it’s

                                                                                                                                        ...   ...

                                                                                                                However

                                                                                                                                      158     What a lovely scene! It sounds like you’re enjoying a peaceful moment in your backyard.

         1000                                                                                                                         159     You see a llama sleeping in your backyard.

                                                                                                                                      160     You see a llama sleeping in your backyard.

                                                                                                                                      161     You see a llama sleeping in your backyard.

         1500

Token rank









                                                                                                                                      162     我在我的后院看到一只睡觉的羊驼。(I see a sleeping llama in my backyard.)

                                                                                                                                        ...   ...

         2000                                                                                                                         399     我在后院看到一只睡着的羊。(I see an asleep sheep in the backyard.)

                                                                                                                                      400     I see a llama sleeping in my backyard.

                                                                                                                                      450     I see a llama sleeping in my backyard.

         2500                                                                                                                         451     我看到我后院里睡着的山羊。(I see the asleep goat in my backyard.)

                                                                                                                                        ...   ...

                                                                                                                                      527     我看到一只睡觉的羊在后院里。(I see a sleeping sheep in the backyard.)

         3000

                                                                                                                                      528     我看到一只睡觉的山上的山上睡觉。(I see a sleeping on the mountain sleeping on the mountain.)

                                                                                                                                      650     我看到了我的后院里看到了我的后院里看到了我的后后后后 (I see in my backyard see in my backyard see my back back)

         3500                                                                                                                         651     我看到我家里看到我家里里里里里里里里里里里里 (I see in my house see in my house in in in in)

                                                                                                                                      659     I see a see a see a see a see a see a see a see a see a see

                                                                                                                                      715     assistant.assistant.assistant.assistant.assistant.assistant.assistant.assistant.assistant.assistant.

         4000                                                                                                                           ...   ...

                   0   64   128   192   256   320   384   448   512   576   640   704   768   832   896   960   1024

                                                          Removed heads



Figure 2. Prompt Llama3.18B-inst with “I see a llama sleeping in my backyard.”, and remove attention heads from the full model by head

weight of en-zh translation task in ascending order. Left: With the removal of attention heads, changes of token ranks in the first generated

token. Blue lines indicate the original top-5 tokens and the red line indicates the target token “我” (I) for translation. Right: Generated

outputs of the model after removing different amounts of attention heads.



ments, We find that attention heads selected by the mask                                                                       Table 6. PPL of explicit translation tasks from English to other

form such pathways in the model, and disrupting or selec-                                                                      languages when applying different masks on Llama3.18B-inst . We

tively masking these heads significantly alters the model’s                                                                    remove attention heads from the full mask 1 that: “all” - used by

task performance. We further reveal that these heads tend                                                                      all 42 translation tasks, “en” - used by 12 translation tasks related

                                                                                                                               to English, and “unused” - not used by any translation tasks.

to shift the model’s original behavior towards the task func-

tionality, and such a pathway effect is unlikely caused by                                                                      Method                            # of heads       en-zh      en-fr       en-es      en-de       en-ru      en-ar

paying more attention to certain tokens.                                                                                        Instruction                         1024           1.091      0.619       0.550      0.627       0.954      1.303

                                                                                                                                w/ 1\all                             847           4.322      4.129       4.149      4.406       5.008      5.441

Attention heads form critical, interdependent functional                                                                        w/ random 1\all                      847           2.122      0.792       0.864      1.248       1.237      2.578

pathways inside the model We first want to know how                                                                             w/ 1\en                              741           7.029      6.137       6.396      6.511       6.903      7.011

masking certain attention heads can switch the model’s be-                                                                      w/ random 1\en                       741           3.325      1.480       2.136      1.540       2.619      2.972

havior from instruction-following towards task functionality.                                                                   w/ 1\unused                          977           1.064      0.577       0.497      0.585       0.924      1.269

                                                                                                                                w/ random 1\unused                   977           1.112      0.688       0.705      0.603       1.020      1.369

One way to probe the behavior changes is progressively

removing attention heads one by one from the full model.

On model Llama3.18B-inst and the en-zh translation task, we                                                                     Specifically, we observe that when attention heads are re-

start with the attention head that has the minimum weight in                                                                    moved, there are numerous abrupt, drastic changes in token

M, remove heads in the weight ascending order, and check                                                                        ranks. If the attention heads worked independently, then

the changes in the generated responses. As shown in Figure                                                                      firstly removing those heads that significantly promote the

2, the model experiences multiple stages in behaviors:                                                                          target token rank would accelerate the behavior shift of the

                                                                                                                                model. However, this influential removal order actually de-

                                                                                                                                lays the functionality switch (see more in Appendix C.3).

             • Stage 1: The model can still preserve the functional-

                                                                                                                                This suggests that the behavior changes are not caused by

               ity as an instruction model, but when approximately

                                                                                                                                removing certain independent attention heads, but are built

               100 attention heads are removed, the rank of the tar-

                                                                                                                                upon the removal of all previously removed attention heads.

               get translation token (red line) experiences a drastic

               increase. This surge indicates that the model’s transla-                                                        Considering such dependency between attention heads, if

               tion functionality begins to emerge.                                                                            we take the selected attention heads as nodes and connect

                                                                                                                               them with edges, then we can get an interdependent func-

             • Stage 2: After removing 158 attention heads, the model

                                                                                                                               tional pathway that influence model behaviors. To verify

               undergoes a rapid transition, and starting from the

                                                                                                                               the impact of such head pathways on model functionality,

               removal of the 162nd head, it shifts from its original

                                                                                                                               we initialize the head weights M with negative values (so

               instruction-following behavior to a translation behavior.

                                                                                                                               that initial σ(M) ≈ 0) when training the mask M. This

               This task functionality begins to dominate, and further

                                                                                                                               approach yields us masks with fewer and more task-specific

               removal of attention heads causes the rankings of initial

                                                                                                                               attention heads while slightly damaging language capability.

               top tokens (blue lines) to drop rapidly.

                                                                                                                               We train these masks on 42 pairs of translation tasks, iden-

             • Stage 3: As more attention heads are removed, after                                                             tify the heads that are commonly used or unused, remove

               528 heads, the model’s language processing ability                                                              these common heads from the model and evaluate PPL on

               begins to lose, and the generated tokens will become                                                            translation tasks. As these common heads are used in every

               meaningless in the end. This is expected as the model                                                           translation task, we can consider them as key components

               has lost the majority of its attention heads.                                                                   of the translation function pathway. Within our expectation,



                                                                                                                          6

