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

question: how would you go about saving a control vector for later use #23

Closed
vpicone opened this issue Mar 18, 2024 · 4 comments
Closed

Comments

@vpicone
Copy link

vpicone commented Mar 18, 2024

Perhaps a naive question, but rather than training a control vector with each run. How might I go about saving it for inference later?

@vgel
Copy link
Owner

vgel commented Mar 18, 2024

You can export it for use with llama.cpp with export_gguf, but I haven't written a method to read that gguf file back in for HuggingFace use yet.

In the meantime, you should be able to use np.save to save the dataclass as a dictionary, and then reconstitute it that way:

import dataclasses
import numpy as np
...
v = ControlVector.train(...)
np.save("vector.npy", dataclasses.asdict(v))

# later...
v = ControlVector(**np.load("vector.npy", allow_pickle=True).tolist())

Hope this helps!

@l1mc
Copy link

l1mc commented Mar 29, 2024

Hi @vgel,

Thanks for the helpful insight on saving a control vector for later use. I noticed that you mentioned the ability to export a control vector with export_gguf for use with llama.cpp. Could you provide an example or guide on how to perform this export?

I found a tutorial on How to convert HuggingFace model to GGUF format. However, I found it difficult to apply this method described here in a Jupyter Notebook (for example, the tutorial ipynb you provided).

Thanks!

@vgel
Copy link
Owner

vgel commented May 24, 2024

@l1mc

Hi @vgel,

Thanks for the helpful insight on saving a control vector for later use. I noticed that you mentioned the ability to export a control vector with export_gguf for use with llama.cpp. Could you provide an example or guide on how to perform this export?

I found a tutorial on How to convert HuggingFace model to GGUF format. However, I found it difficult to apply this method described here in a Jupyter Notebook (for example, the tutorial ipynb you provided).

Thanks!

Sorry, didn't see this earlier! Once you have a vector trained with (e.g.) vector = ControlVector.train(...), you can simply export it with:

vector.export_gguf("vector.gguf")

If you're running a version with #34 applied, you can also then import the vector back to Python with

vector = ControlVector.import_gguf("vector.gguf")

or you can use it with llama.cpp using the ./main runner:

$ ./main ... --control-vector vector.gguf --control-vector-layer-range 14 26 ...

Hope this helps!

@vgel
Copy link
Owner

vgel commented May 25, 2024

Closing this as addressed by #34

@vgel vgel closed this as completed May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants