-
Notifications
You must be signed in to change notification settings - Fork 162
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
Use chat templates for vision models #173
base: main
Are you sure you want to change the base?
Use chat templates for vision models #173
Conversation
5c8ccfa
to
3ac6296
Compare
@davidkoski, I made some changes, and it seems to work in VLMEval. Do you have any thoughts on this? |
3ac6296
to
4547cf1
Compare
I think
|
The solution in my latest commit uses the chat template (correctly, I think) to create a prompt like this:
However, in order for the model to work, it looks like we need to replace the single let mergeLength = config.mergeSize * config.mergeSize
let repeatedPadding = Array(repeating: "<|image_pad|>", count: thw.product / mergeLength).joined() |
347ccc5
to
806c7f2
Compare
I now have something that works, although it still needs to take into account the case where multiple images are included. |
0f68fd2
to
ed03ae5
Compare
@davidkoski, I found it quite difficult to reason about the code because of how some of the variables and parameters were named. What do you think about calling an array of type |
it sounds ok to me, though they aren't the frames themselves but the positions of the frames in one of the arrays (maybe not in the final array). I think try |
Right, that is this part: I think the sequence from the python side is roughly:
One issue we have on the swift side is step 1 and step 3 occur in the same function in swift-transformers and we don't have a hook for step 2. |
e9c7a02
to
8cb233b
Compare
8959c45
to
3e50263
Compare
@DePasqualeOrg it looks like the swift-transformers side (which includes Jinja) is ready to go and would solve some issues with text models. Do you want to prepare a PR for picking that up (since it is mostly your work)? If you are busy I can get that ready. |
I think #185 accomplishes that. Xcode is showing the latest patch versions of the packages when I open mlx-swift-examples. Or is there something I'm missing? huggingface/swift-transformers#151 still needs to be merged before this PR, since it expands the type of a message from |
031e47f
to
db97052
Compare
I've verified that this also works with multiple images, although I'll need to do further testing to check the model's performance. I noticed that Qwen 2 VL tends to respond in Mandarin unless prompted otherwise. |
Yeah, I noticed that too. At least the responses seemed correct per google translate :-) |
db97052
to
332551a
Compare
0b746f4
to
db883ff
Compare
This is now ready for review. |
db883ff
to
408e7a8
Compare
I now need to make some significant changes because the video pull request was merged before this one. |
This is a test of my PR to Swift Jinja, which should enable chat templates to be used for vision language models that have a chat template. I've started to set things up, but I need some pointers on how to integrate the image into the messages.