Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contrast Vector - Add Code for Generation? #28

Open
RobertMcCarthy97 opened this issue Dec 1, 2023 · 11 comments
Open

Contrast Vector - Add Code for Generation? #28

RobertMcCarthy97 opened this issue Dec 1, 2023 · 11 comments
Labels
enhancement New feature or request

Comments

@RobertMcCarthy97
Copy link

Hi,

I was wondering if code demonstrating how to use the contrast vector for text generation could be pushed? (Ideally for a 7B model!)

I am quite unclear on how to convert the contrast vector code from honesty_control_TQA.ipynb to allow for generation. And I am finding it difficult to parse all the contrast vector implementation details from the paper.

This would be very useful, so would really appreciate it!

Thanks,
Robert

@RobertMcCarthy97 RobertMcCarthy97 changed the title Contrast Vector - Code for Generation Contrast Vector - Add Code for Generation? Dec 1, 2023
@justinphan3110cais
Copy link
Collaborator

Yes, we are planning to fully support this in the rep-control pipeline soon. Will keep this thread update

@RobertMcCarthy97
Copy link
Author

Great to hear, thanks!

@wj210
Copy link

wj210 commented Dec 7, 2023

Hi, can i clarify regarding in rep_control_pipeline.py , how is self.wrapped_model used?

during the init fn:
`
self.wrapped_model = WrappedReadingVecModel(model, tokenizer)

    self.wrapped_model.unwrap()
    self.wrapped_model.wrap_block(layers, block_name=block_name)
    self.block_name = block_name
    self.layers = layers
    super().__init__(model=model, tokenizer=tokenizer, **kwargs)

`

model is still set to model, and outputs = super().__call__(text_inputs, **kwargs), doesn't; it call the original model? how is the activations integrated into the outputs in this case?

Is the output text from the jupyter notebook example using a normal model call or generate fn?

Thanks!

@justinphan3110cais
Copy link
Collaborator

@wj210, you can either use wrapped_model.generate or model.generate when activation is set by wrapped_model. An example is showed the last cell of this notebook

@justinphan3110cais justinphan3110cais added the enhancement New feature or request label Dec 7, 2023
@wj210
Copy link

wj210 commented Dec 8, 2023

it shows outputs = wrapped_model(**encoded_inputs.to(model.device), output_hidden_states=True)['hidden_states'], but the outputs are overriden by the later model.generate

also, if i use wrappedmodel.generate, it doesn't take in other generate args such as do_sample, temp, etc...?
def generate(self, prompt, max_new_tokens=100, random_seed=0, use_cache=True):

@justinphan3110cais
Copy link
Collaborator

The
outputs = wrapped_model(**encoded_inputs.to(model.device), output_hidden_states=True)['hidden_states'] should be deleted. MB and thanks for the catch.

I think you may have an older version of the code for wrapped_model.generate

@merlinarer
Copy link

Hello, any progress on this thread ? or Just give us some instructions so that we can help to achieve it.

@justinphan3110cais
Copy link
Collaborator

justinphan3110cais commented Jan 4, 2024

Hi @merlinarer @RobertMcCarthy97, sorry for the late updates. We have just update the TQA_honesty notebook that support Llama and Mistral models (CasadingLlamaForCausalLM, CasadingMistralForCausalLM)

@merlinarer
Copy link

Hi @merlinarer @RobertMcCarthy97, sorry for the late updates. We have just update the TQA_honesty notebook that support Llama and Mistral models (CasadingLlamaForCausalLM, CasadingMistralForCausalLM)

Awesome!! Is there any guide for us to support other models ?

@justinphan3110cais
Copy link
Collaborator

justinphan3110cais commented Jan 7, 2024

We have just updated the code a bit to include generation honesty_contrast_vec_TQA_generation.

@merlinarer let us know what other architecture you would like to support. ContrastVecMistralForCausalLM (changed from CasadingMistralForCausalLM) should works with most of the Mistral based models like zephyr, openchat, etc.

@YerongLi
Copy link

The notebook only showed how to use ContrastVecMistralForCausalLM without fine-tuning. I am wondering if we don't go through the tuning process in Algo 1, will the performance good as paper shown on TQA datasets?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants