repeng icon indicating copy to clipboard operation
repeng copied to clipboard

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

Open vpicone opened this issue 1 year ago • 2 comments

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

vpicone avatar Mar 18 '24 18:03 vpicone

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!

vgel avatar Mar 18 '24 22:03 vgel

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!

l1mc avatar Mar 29 '24 04:03 l1mc

@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 avatar May 24 '24 23:05 vgel

Closing this as addressed by #34

vgel avatar May 25 '24 01:05 vgel