How to convert torchtune .pt output files? #1201
-
I did a fine-tuning run llama3-8b using a parquet dataset and it produced a couple of checkpoint .pt files. Can these be converted into something like gguf for usage in other inference platforms? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @troy256 thanks for creating the discussion and sorry for the delayed response here. Are you using the Meta checkpoint format or the HF checkpoint format in your fine-tuning run (i.e. what is the checkpointer used here in your config)? (The default for our Llama3-8B configs should be Meta checkpointer, so if you didn't change anything it's probably that one.) Currently it should be possible to convert HF-style checkpoints to GGUF, but this is something that's not yet well-tested (I am hoping we can add some kind of test for this soon). At least for HF-style checkpoints you can try following the process in this discussion. If you're using the Meta checkpoint you can try this as well, but I suspect it will be more challenging. I will look into changing the default checkpoint format for our Llama3-8B fine-tuning configs from Meta to HF (most of our other configs use HF format anyways). Either way if you do try to follow the process outlined in the above discussion please let me know any errors you run into and we can help debug. |
Beta Was this translation helpful? Give feedback.
-
@troy256 personally I would expect (1) re-run your fine-tuning job but replace Meta checkpointer with HF checkpointer. This isn't ideal since you have to re-run the fine-tuning job again, but the actual changes to do it should be pretty straightforward. You just need to make sure you have the HF versions of the checkpoints downloaded, you should be able to run something like this to do it:
Then change the checkpointer in your fine-tuning run, should be from something like this to something like this:
(2) Alternatively, you can manually remap the checkpoints you have saved already into HF format. This would basically be a two-hop conversion: you'd need to convert from Meta format to torchtune format, then from torchtune format to HF format. So it'd probably start like this:
To convert to HF format you can even use the checkpointer directly. You should run the
This should save HF safetensors files to the checkpointer's output_dir containing the remapped weights of your fine-tuned checkpoint. Once you've done one of these two you should be able to try out |
Beta Was this translation helpful? Give feedback.
@troy256 personally I would expect
convert_hf_to_gguf.py
to be a decent starting point (though I haven't tried it myself). But first you would need to convert from the Meta checkpoint format into the HF checkpoint format. There are basically two ways you can do this:(1) re-run your fine-tuning job but replace Meta checkpointer with HF checkpointer. This isn't ideal since you have to re-run the fine-tuning job again, but the actual changes to do it should be pretty straightforward. You just need to make sure you have the HF versions of the checkpoints downloaded, you should be able to run something like this to do it: