MCPcopy Create free account

hub / github.com/boyiwei/alignment-attribution-code / functions

Functions99 in github.com/boyiwei/alignment-attribution-code

↓ 20 callersFunctionfind_layers
Recursively find the layers of a certain type in a module. Args: module (nn.Module): PyTorch module. layers (list): List of
lib/prune.py:17
↓ 14 callersFunctionreturn_given_alpha
(alpha, sort_res, W_metric, tmp_metric, sum_before)
lib/prune.py:140
↓ 13 callersFunctioneval_attack
Evaluate the attack performance of a given model on AdvBench. Args: model (object): The model object to be evaluated. tokeni
lib/eval.py:257
↓ 13 callersFunctionget_loaders
( name, nsamples=128, seed=0, seqlen=2048, tokenizer=None, disentangle=False )
lib/data.py:114
↓ 7 callersMethodadd_batch
(self, inp, out)
lib/ablate.py:29
↓ 5 callersFunctionadd_batch
(name, tar)
lib/prune.py:332
↓ 5 callersFunctionmake_Act
(model, verbose=False)
lib/model_wrapper.py:91
↓ 5 callersFunctionprepare_calibration_input
(model, dataloader, device, nsamples)
lib/prune.py:93
↓ 4 callersFunctioneval_ppl
(args, model, tokenizer, device=torch.device("cuda:0"))
lib/eval.py:81
↓ 3 callersFunction_prune_core
data aware
lib/model_wrapper.py:321
↓ 3 callersFunctionapply_prompt_template
Apply a prompt template to a dataset of plain queries. Add system prompt, user prompt, <<SYS>> tags, [INST] tags, etc.. Args: pro
lib/prompt_utils.py:87
↓ 3 callersFunctioneval_zero_shot
( model_name, model, tokenizer, task_list=[ "boolq", "rte", "hellaswag
lib/eval.py:205
↓ 3 callersFunctionget_llm
(model_name, cache_dir="llm_weights")
main.py:42
↓ 3 callersFunctionmake_Act
(model, verbose=False)
main_low_rank_diff.py:77
↓ 3 callersFunctionmake_Act
(model, verbose=False)
lib/model_wrapper_low.py:76
↓ 3 callersFunctionmake_low_rank
( args, model, tokenizer, device=torch.device("cuda:0"), prune_data="wikitext" )
lib/model_wrapper_low.py:128
↓ 3 callersFunctionrevert_Act_to_Linear
Reverts ActLinear modules back to their original nn.Linear layers.
lib/model_wrapper.py:115
↓ 2 callersFunctionadd_batch_extra
(name, tar)
lib/prune.py:775
↓ 2 callersFunctionclear_act_buffer
(act_model)
main_low_rank_diff.py:123
↓ 2 callersFunctionclear_act_buffer
(act_model)
lib/model_wrapper.py:137
↓ 2 callersFunctionclear_act_buffer
(act_model)
lib/model_wrapper_low.py:122
↓ 2 callersMethodclear_act_buffer
(self)
main_low_rank_diff.py:29
↓ 2 callersMethodclear_act_buffer
(self)
lib/model_wrapper_low.py:28
↓ 2 callersMethodfasterprune
( self, args, sparsity, mask=None, prune_n=0, prune_m=0,
lib/ablate.py:86
↓ 2 callersMethodfree
(self)
lib/ablate.py:187
↓ 2 callersFunctionget_align
(nsamples, seed, seqlen, tokenizer, disentangle=False, mode="base")
lib/data.py:22
↓ 2 callersFunctionget_llm
(model_name, cache_dir="llm_weights")
rewind_ft_model.py:27
↓ 2 callersFunctionget_llm
(model_name, cache_dir="llm_weights")
main_low_rank_diff.py:334
↓ 2 callersFunctionnot_matched
(o)
lib/eval.py:59
↓ 2 callersFunctionprune_wandg
( args, model, tokenizer, model_base=None, device=torch.device("cuda:0"), prune_n=0,
lib/model_wrapper.py:241
↓ 1 callersMethod__init__
(self, model, mask)
main_low_rank_diff.py:62
↓ 1 callersMethod__init__
(self, model, mask)
lib/model_wrapper.py:76
↓ 1 callersMethod__init__
(self, model, mask)
lib/model_wrapper_low.py:61
↓ 1 callersFunctioncheck_sparsity
(model)
lib/prune.py:41
↓ 1 callersMethodclear_act_buffer
(self)
lib/model_wrapper.py:31
↓ 1 callersFunctioneval_ppl_wikitext
(model, testenc, bs=1, device=None)
lib/eval.py:154
↓ 1 callersFunctionget_alpaca
(nsamples, seed, seqlen, tokenizer, disentangle=False, dataset="alpaca")
lib/data.py:71
↓ 1 callersFunctionget_llm
(model_name, cache_dir="llm_weights")
main_low_rank.py:40
↓ 1 callersFunctionget_llm
(model_name, cache_dir="llm_weights")
lib/model_wrapper.py:534
↓ 1 callersFunctionget_llm
(model_name, cache_dir="llm_weights")
lib/model_wrapper_low.py:281
↓ 1 callersMethodget_mag_mask
(self, sparsity, prunen, prunem)
lib/ablate.py:67
↓ 1 callersFunctionget_mask
Save mask for the unstructured pruned model (for ft-attack evaluation). `neg_prune`: - if `args.neg_prune` is False (bottom pruning),
lib/prune.py:2041
↓ 1 callersFunctionget_prompt_template
(prompt_template_style="base")
lib/prompt_utils.py:7
↓ 1 callersMethodget_wanda_mask
(self, sparsity, prunen, prunem)
lib/ablate.py:48
↓ 1 callersFunctionget_wikitext2
(nsamples, seed, seqlen, tokenizer)
lib/data.py:63
↓ 1 callersFunctionmain
()
rewind_ft_model.py:39
↓ 1 callersFunctionmain
()
main_low_rank.py:59
↓ 1 callersFunctionmain
()
main.py:61
↓ 1 callersFunctionmake_low_rank
prune_data_pos: retain most useful (total_rank - rank_pos) ranks prune_data_neg: remove most useful (total_rank - rank_neg) ranks final_
main_low_rank_diff.py:129
↓ 1 callersFunctionpattern_match
(patterns, source_list)
lib/eval.py:224
↓ 1 callersFunctionprune_ablate
(args, model, tokenizer, dev, prune_n=0, prune_m=0)
lib/prune.py:1910
↓ 1 callersFunctionprune_attention_head
Prune the attention_heads based on the probing results. Still not supporting reover from base. Only support Llama-2-7b-chat-hf Args: args
lib/prune.py:2068
↓ 1 callersFunctionprune_magnitude
( args, model, tokenizer, model_base=None, device=torch.device("cuda:0"), prune_n=0,
lib/prune.py:199
↓ 1 callersFunctionprune_random
( args, model, tokenizer, model_base=None, device=torch.device("cuda:0"), prune_n=0,
lib/prune.py:151
↓ 1 callersFunctionprune_sparsegpt
(args, model, tokenizer, dev, prune_n=0, prune_m=0)
lib/prune.py:1791
↓ 1 callersFunctionprune_wanda
( args, model, tokenizer, model_base=None, device=torch.device("cuda:0"), prune_n=0,
lib/prune.py:255
↓ 1 callersFunctionprune_wanda_decouple_activations
Compute wanda score based on the difference between the align activation and misalign activation (In an online way, do not need to load wanda sco
lib/prune.py:641
↓ 1 callersFunctionprune_wanda_v2
( args, model, tokenizer, model_base=None, device=torch.device("cuda:0"), prune_n=0,
lib/model_wrapper.py:143
↓ 1 callersFunctionprune_wandg_set_difference
( args, model, tokenizer, model_base=None, device=torch.device("cuda:0"), prune_n=0,
lib/prune.py:1612
↓ 1 callersFunctionrevert_Act_to_Linear
Reverts ActLinear modules back to their original nn.Linear layers.
main_low_rank_diff.py:101
↓ 1 callersFunctionrevert_Act_to_Linear
Reverts ActLinear modules back to their original nn.Linear layers.
lib/model_wrapper_low.py:100
Method__enter__
(self)
main_low_rank_diff.py:50
Method__enter__
(self)
main_low_rank_diff.py:66
Method__enter__
(self)
lib/model_wrapper.py:64
Method__enter__
(self)
lib/model_wrapper.py:80
Method__enter__
(self)
lib/model_wrapper_low.py:49
Method__enter__
(self)
lib/model_wrapper_low.py:65
Method__exit__
(self, exc_type, exc_val, exc_tb)
main_low_rank_diff.py:55
Method__exit__
(self, exc_type, exc_val, exc_tb)
main_low_rank_diff.py:71
Method__exit__
(self, exc_type, exc_val, exc_tb)
lib/model_wrapper.py:69
Method__exit__
(self, exc_type, exc_val, exc_tb)
lib/model_wrapper.py:85
Method__exit__
(self, exc_type, exc_val, exc_tb)
lib/model_wrapper_low.py:54
Method__exit__
(self, exc_type, exc_val, exc_tb)
lib/model_wrapper_low.py:70
Method__init__
(self, base: nn.Linear)
main_low_rank_diff.py:23
Method__init__
(self, model)
main_low_rank_diff.py:47
Method__init__
(self, layer)
lib/ablate.py:14
Method__init__
(self, module)
lib/prune.py:111
Method__init__
(self, base: nn.Linear)
lib/model_wrapper.py:21
Method__init__
(self, model)
lib/model_wrapper.py:61
Method__init__
(self, input_ids)
lib/data.py:17
Method__init__
(self, layer)
lib/sparsegpt.py:15
Method__init__
(self, base: nn.Linear)
lib/model_wrapper_low.py:22
Method__init__
(self, model)
lib/model_wrapper_low.py:46
Method__init__
(self, layer, layer_id=0, layer_name="none")
lib/layerwrapper.py:11
Methodadd_batch
(self, inp, out)
lib/sparsegpt.py:28
Methodadd_batch
tar: batch_size * seq_len, inp corresponding to the position where tar == -100 will be ignored
lib/layerwrapper.py:25
Functioncheck_sparsity_layerwise
(model)
lib/prune.py:68
Functioneval_ppl_wikitext_train
(model, trainloader, bs=1, device=None)
lib/eval.py:100
Methodfasterprune
(self, sparsity, prune_n=0, prune_m=0, blocksize=128, percdamp=0.01)
lib/sparsegpt.py:43
Methodforward
(self, x)
main_low_rank_diff.py:32
Methodforward
(self, inp, **kwargs)
lib/prune.py:115
Methodforward
(self, x)
lib/model_wrapper.py:35
Methodforward
(self, x)
lib/model_wrapper_low.py:31
Methodfree
(self)
lib/sparsegpt.py:126
Functionget_sentence_embedding
(model, tokenizer, sentence)
lib/eval.py:68
Functionprune_wanda_decouple_activation_norms
Compute wanda score based on the difference between tow activation norms (In an online way, do not need to load wanda score from file) Compu
lib/prune.py:1125
Functionprune_wandg_v1
( args, model, tokenizer, model_base=None, device=torch.device("cuda:0"), prune_n=0,
lib/model_wrapper.py:191
Functionset_seed
(seed)
lib/data.py:10
Functiontmp
(_, inp, out)
lib/prune.py:333