From 6e2fb94923f817726f2da65acb7d8ff35cbed0d3 Mon Sep 17 00:00:00 2001 From: Jana Date: Tue, 13 May 2025 13:23:29 +0200 Subject: [PATCH 1/6] FIXED typechecked --- llm_transparency_tool/models/tlens_model.py | 30 +++++++++---------- llm_transparency_tool/routes/contributions.py | 10 +++---- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/llm_transparency_tool/models/tlens_model.py b/llm_transparency_tool/models/tlens_model.py index 9342308..a6a66c4 100644 --- a/llm_transparency_tool/models/tlens_model.py +++ b/llm_transparency_tool/models/tlens_model.py @@ -158,24 +158,24 @@ def batch_size(self) -> int: raise self._run_exception return self._last_run.logits.shape[0] - @typechecked + #@typechecked # Jana: commented out because of colab issues, TODO: in documentation aufnehmen def tokens(self) -> Int[torch.Tensor, "batch pos"]: if not self._last_run: raise self._run_exception return self._last_run.tokens - @typechecked + #@typechecked def tokens_to_strings(self, tokens: Int[torch.Tensor, "pos"]) -> List[str]: return self._model.to_str_tokens(tokens) - @typechecked + #@typechecked def logits(self) -> Float[torch.Tensor, "batch pos d_vocab"]: if not self._last_run: raise self._run_exception return self._last_run.logits @torch.no_grad() - @typechecked + #@typechecked def unembed( self, t: Float[torch.Tensor, "d_model"], @@ -197,13 +197,13 @@ def _get_block(self, layer: int, block_name: str) -> torch.Tensor: # ================= Methods related to the residual stream ================= - @typechecked + #@typechecked def residual_in(self, layer: int) -> Float[torch.Tensor, "batch pos d_model"]: if not self._last_run: raise self._run_exception return self._get_block(layer, "hook_resid_pre") - @typechecked + #@typechecked def residual_after_attn( self, layer: int ) -> Float[torch.Tensor, "batch pos d_model"]: @@ -211,7 +211,7 @@ def residual_after_attn( raise self._run_exception return self._get_block(layer, "hook_resid_mid") - @typechecked + #@typechecked def residual_out(self, layer: int) -> Float[torch.Tensor, "batch pos d_model"]: if not self._last_run: raise self._run_exception @@ -219,14 +219,14 @@ def residual_out(self, layer: int) -> Float[torch.Tensor, "batch pos d_model"]: # ================ Methods related to the feed-forward layer =============== - @typechecked + #@typechecked def ffn_out(self, layer: int) -> Float[torch.Tensor, "batch pos d_model"]: if not self._last_run: raise self._run_exception return self._get_block(layer, "hook_mlp_out") @torch.no_grad() - @typechecked + #@typechecked def decomposed_ffn_out( self, batch_i: int, @@ -238,7 +238,7 @@ def decomposed_ffn_out( processed_activations = self._get_block(layer, "mlp.hook_post")[batch_i][pos] return torch.mul(processed_activations.unsqueeze(-1), self._model.blocks[layer].mlp.W_out) - @typechecked + #@typechecked def neuron_activations( self, batch_i: int, @@ -247,7 +247,7 @@ def neuron_activations( ) -> Float[torch.Tensor, "hidden"]: return self._get_block(layer, "mlp.hook_pre")[batch_i][pos] - @typechecked + #@typechecked def neuron_output( self, layer: int, @@ -257,13 +257,13 @@ def neuron_output( # ==================== Methods related to the attention ==================== - @typechecked + #@typechecked def attention_matrix( self, batch_i: int, layer: int, head: int ) -> Float[torch.Tensor, "query_pos key_pos"]: return self._get_block(layer, "attn.hook_pattern")[batch_i][head] - @typechecked + #@typechecked def attention_output_per_head( self, batch_i: int, @@ -273,7 +273,7 @@ def attention_output_per_head( ) -> Float[torch.Tensor, "d_model"]: return self._get_block(layer, "attn.hook_result")[batch_i][pos][head] - @typechecked + #@typechecked def attention_output( self, batch_i: int, @@ -283,7 +283,7 @@ def attention_output( return self._get_block(layer, "hook_attn_out")[batch_i][pos] @torch.no_grad() - @typechecked + #@typechecked def decomposed_attn( self, batch_i: int, layer: int ) -> Float[torch.Tensor, "pos key_pos head d_model"]: diff --git a/llm_transparency_tool/routes/contributions.py b/llm_transparency_tool/routes/contributions.py index cc6ddcb..03fd8bb 100644 --- a/llm_transparency_tool/routes/contributions.py +++ b/llm_transparency_tool/routes/contributions.py @@ -13,7 +13,7 @@ @torch.no_grad() -@typechecked +#@typechecked def get_contributions( parts: torch.Tensor, whole: torch.Tensor, @@ -53,7 +53,7 @@ def get_contributions( @torch.no_grad() -@typechecked +#@typechecked def get_contributions_with_one_off_part( parts: torch.Tensor, one_off: torch.Tensor, @@ -90,7 +90,7 @@ def get_contributions_with_one_off_part( @torch.no_grad() -@typechecked +#@typechecked def get_attention_contributions( resid_pre: Float[torch.Tensor, "batch pos d_model"], resid_mid: Float[torch.Tensor, "batch pos d_model"], @@ -125,7 +125,7 @@ def get_attention_contributions( @torch.no_grad() -@typechecked +#@typechecked def get_mlp_contributions( resid_mid: Float[torch.Tensor, "batch pos d_model"], resid_post: Float[torch.Tensor, "batch pos d_model"], @@ -143,7 +143,7 @@ def get_mlp_contributions( @torch.no_grad() -@typechecked +#@typechecked def get_decomposed_mlp_contributions( resid_mid: Float[torch.Tensor, "d_model"], resid_post: Float[torch.Tensor, "d_model"], From a4c26e4c510bd899ce74fda4fdd0510dd159bf3b Mon Sep 17 00:00:00 2001 From: Jana Date: Tue, 13 May 2025 15:06:04 +0200 Subject: [PATCH 2/6] FIXED tlens_model --- llm_transparency_tool/models/tlens_model.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/llm_transparency_tool/models/tlens_model.py b/llm_transparency_tool/models/tlens_model.py index a6a66c4..3963433 100644 --- a/llm_transparency_tool/models/tlens_model.py +++ b/llm_transparency_tool/models/tlens_model.py @@ -126,7 +126,8 @@ def _model(self): tlens_model.set_tokenizer(self.hf_tokenizer, default_padding_side="left") tlens_model.set_use_attn_result(True) - tlens_model.set_use_attn_in(False) + # Jana: auskommentiert, weil colab mit GQA einen Fehler geworfen hat + #tlens_model.set_use_attn_in(False) tlens_model.set_use_split_qkv_input(False) return tlens_model From 13777d88af8134d5e8ec6891d847679aeec71b97 Mon Sep 17 00:00:00 2001 From: Jana Date: Wed, 28 May 2025 14:23:49 +0200 Subject: [PATCH 3/6] ADDED best, corr2false, false2corr formal sents for llama --- best_formal.txt | 6 ++++++ corr2false_formal.txt | 8 ++++++++ false2corr_formal.txt | 9 +++++++++ 3 files changed, 23 insertions(+) create mode 100644 best_formal.txt create mode 100644 corr2false_formal.txt create mode 100644 false2corr_formal.txt diff --git a/best_formal.txt b/best_formal.txt new file mode 100644 index 0000000..8f27628 --- /dev/null +++ b/best_formal.txt @@ -0,0 +1,6 @@ +Images from television of ten fired her imagination +Home truths +SWEENEY BIG Cheese +WORLD PARTY animal +Apart from Fedorov, that fellow who gave us the slip +I beat a heavy retreat diff --git a/corr2false_formal.txt b/corr2false_formal.txt new file mode 100644 index 0000000..e2a8aee --- /dev/null +++ b/corr2false_formal.txt @@ -0,0 +1,8 @@ +Pleased with the group's healthy sales, Red Rhino allowed the band the luxury of a colour sleeve for their third release, the double A-side, ‘This Boy Can Wait’ and ‘You Should Always Keep In Touch +Whitbread had no formal education and seems to have been the archetypal self-made man +Their answers result in the supreme irony of lorry-loads of young men, having scraped together +The Society is keeping in close touch +In this instance we are again studying a very real struggle, with gangs looting, scavenging and turning to organised crime as a means of scraping together +But Mr Kaifu is in no mood to let anyone steal his thunder +With me that rings a warning bell +Like the constable in the story, use any cover to keep your attacker at bay diff --git a/false2corr_formal.txt b/false2corr_formal.txt new file mode 100644 index 0000000..b546d2a --- /dev/null +++ b/false2corr_formal.txt @@ -0,0 +1,9 @@ +Organisers of the biggest air rally in Europe say that military red tape +Earlier in this chapter ( p. 70 ) striking a realistic balance +Inevitably, a book such as this harps on +The bottom line is +Rachel kept in touch +It took me breath away +( James Brown, 20/2/88 who made it Single Of The Week along with The Wedding Present's ‘Nobody's Twisting Your Arm +The achievements are well recorded : the Brabazon airliner, the abortive TSR2 fighter plane and Concorde — the fastest white elephant +The word is much used by his closest adviser, Hernando de Soto, author of ‘The Other Path’ — a celebrated study of Peru's huge and dense informal sector of street vendors, cottage industries and red tape From 5e4926b75f7d83b9a82467cbbe5f73e285e7704b Mon Sep 17 00:00:00 2001 From: Jana Grimm Date: Fri, 30 May 2025 09:15:03 +0200 Subject: [PATCH 4/6] ADDED llama 1B-Instruct to config and wrong formal sentences --- config/local.json | 2 +- wrong_formal.txt | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 wrong_formal.txt diff --git a/config/local.json b/config/local.json index 7cf780b..fadd376 100644 --- a/config/local.json +++ b/config/local.json @@ -4,7 +4,7 @@ "debug": true, "models": { "": null, - + "meta-llama/Llama-3.2-1B-Instruct": null, "meta-llama/Meta-Llama-3-8B": null, "meta-llama/Meta-Llama-3-70B": null, "meta-llama/Meta-Llama-3-8B-Instruct": null, diff --git a/wrong_formal.txt b/wrong_formal.txt new file mode 100644 index 0000000..8bc97e4 --- /dev/null +++ b/wrong_formal.txt @@ -0,0 +1,12 @@ +SWEENEY BIG Cheese +But it had been years, even then, since Elvis was top of the Hit Parade, and if all he had to offer the world was slicked-back hair and a sulky pout, the Dead Loss +Not only in Europe, but also in Afghanistan, Africa and East Asia, the Soviet Empire now drew in its horns +I beat a heavy retreat +Home truths +Why not cut the Mustard +Apart from Fedorov, that fellow who gave us the slip +While the credit- driven Anglo economies draw in their horns +Old chestnut +I call the tunes +The writer often called the tune +Far from drawing in his horns \ No newline at end of file From 0799f3a23d9d1291a0342b167519273926ff15d5 Mon Sep 17 00:00:00 2001 From: Jana Grimm Date: Thu, 5 Jun 2025 16:36:37 +0200 Subject: [PATCH 5/6] ADDED all sentence file --- all.txt | 31 +++++++++++++++++++++++++++++++ config/local.json | 2 +- env.yaml | 3 ++- 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 all.txt diff --git a/all.txt b/all.txt new file mode 100644 index 0000000..3ce8c57 --- /dev/null +++ b/all.txt @@ -0,0 +1,31 @@ +Images from television of ten fired her +Home +SWEENEY BIG +WORLD PARTY +Apart from Fedorov, that fellow who gave us the +I beat a heavy +Pleased with the group's healthy sales, Red Rhino allowed the band the luxury of a colour sleeve for their third release, the double A-side, ‘This Boy Can Wait’ and ‘You Should Always Keep In +Whitbread had no formal education and seems to have been the archetypal self-made +Their answers result in the supreme irony of lorry-loads of young men, having scraped +The Society is keeping in close +In this instance we are again studying a very real struggle, with gangs looting, scavenging and turning to organised crime as a means of scraping +But Mr Kaifu is in no mood to let anyone steal his +With me that rings a warning +Like the constable in the story, use any cover to keep your attacker at +Organisers of the biggest air rally in Europe say that military red +Earlier in this chapter ( p. 70 ) striking a realistic +Inevitably, a book such as this harps +The bottom line +Rachel kept in +It took me breath +( James Brown, 20/2/88 who made it Single Of The Week along with The Wedding Present's ‘Nobody's Twisting Your +The achievements are well recorded : the Brabazon airliner, the abortive TSR2 fighter plane and Concorde — the fastest white +The word is much used by his closest adviser, Hernando de Soto, author of ‘The Other Path’ — a celebrated study of Peru's huge and dense informal sector of street vendors, cottage industries and red +But it had been years, even then, since Elvis was top of the Hit Parade, and if all he had to offer the world was slicked-back hair and a sulky pout, the Dead +Not only in Europe, but also in Afghanistan, Africa and East Asia, the Soviet Empire now drew in its +Why not cut the +While the credit- driven Anglo economies draw in their +Old +I call the +The writer often called the +Far from drawing in his \ No newline at end of file diff --git a/config/local.json b/config/local.json index fadd376..9e911b6 100644 --- a/config/local.json +++ b/config/local.json @@ -1,6 +1,6 @@ { "allow_loading_dataset_files": true, - "preloaded_dataset_filename": "sample_input.txt", + "preloaded_dataset_filename": "all.txt", "debug": true, "models": { "": null, diff --git a/env.yaml b/env.yaml index 7d76b23..3a791a5 100644 --- a/env.yaml +++ b/env.yaml @@ -6,7 +6,8 @@ channels: dependencies: - python=3.12 - pytorch - - pytorch-cuda=11.8 + #- pytorch-cuda=11.8 # Jana: Resolve version conflict with idiom installations + - pytorch-cuda - nodejs - yarn - pip From 69f6136005e6387586a5be42b36f7a2a8305fbdb Mon Sep 17 00:00:00 2001 From: Jana Grimm Date: Tue, 10 Jun 2025 17:08:34 +0200 Subject: [PATCH 6/6] ADDED missing sents in all.txt --- all.txt | 4 +++- config/local.json | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/all.txt b/all.txt index 3ce8c57..a41187e 100644 --- a/all.txt +++ b/all.txt @@ -28,4 +28,6 @@ While the credit- driven Anglo economies draw in their Old I call the The writer often called the -Far from drawing in his \ No newline at end of file +Far from drawing in his +Fokker is negotiating with Lockheed to assemble aircraft in America : this would bring Lockheed back into the commercial business , which it quit in 1981 after losing its +BRINGING HOME THE \ No newline at end of file diff --git a/config/local.json b/config/local.json index 9e911b6..ee9ec40 100644 --- a/config/local.json +++ b/config/local.json @@ -51,6 +51,6 @@ "facebook/opt-13b": null, "facebook/opt-30b": null }, - "default_model": "", + "default_model": "meta-llama/Llama-3.2-1B-Instruct", "demo_mode": false }