Views
No views yet
pip install autocontrastive-gen).MultiExitConfiguration that determines model behavior at training and inference, and then loads the model using the dedicated AutoMultiExitModel class. After that, the model can be used with the transformers API like any other model. See the GitHub for detailed usage instructions.1from transformers import AutoTokenizer
2from autocontrastive_gen.modeling.configuration import MultiExitConfiguration
3from autocontrastive_gen.modeling.auto_model import AutoMultiExitModel
4
5# initialize a pre-trained multi-exit model to use auto-contrast between layer 24 and layer 12
6multi_exit_config = MultiExitConfiguration(use_original_head=False,
7 contrast_layer_indices=(24, 12))
8model = AutoMultiExitModel.from_pretrained("IBM/gpt2-medium-multiexit", multi_exit_config=multi_exit_config)
9
10# perform text generation as usual
11tokenizer = AutoTokenizer.from_pretrained("IBM/gpt2-medium-multiexit")
12prompt = tokenizer("humpty dumpty sat on", return_tensors='pt')
13generated_ids = model.generate(**prompt, max_new_tokens=15)
14print(tokenizer.batch_decode(generated_ids))1@inproceedings{gera2023autocontrastive,
2 title={The Benefits of Bad Advice: Autocontrastive Decoding across Model Layers},
3 author={Gera, Ariel and Friedman, Roni and Arviv, Ofir and Gunasekara, Chulaka and Sznajder, Benjamin and Slonim, Noam and Shnarch, Eyal},
4 booktitle={Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)},
5 month={july},
6 address={Toronto, Canada},
7 year={2023}
8}