-
Notifications
You must be signed in to change notification settings - Fork 906
Support the generation of JanusPro models #3218
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
618eaaa
add transformers in gitignore
DaozeZhang 8fd4051
fix a typo bug in text-caps
DaozeZhang f7a3eea
Merge branch 'modelscope:main' into main
DaozeZhang add49e5
add .run into gitignore
DaozeZhang 4f43621
Merge commit 'f7a3eeaf0c57a100e985276fa783239f21fa9ee6'
DaozeZhang 40d3ad0
add vlmeval to gitignore
DaozeZhang a3ae3ca
Merge commit '9bae58c9dc3015855bcd6a75794eb9c3947cb476'
DaozeZhang 818d0fd
add my_model/ to gitignore
DaozeZhang 619a4bd
Merge commit '704381f2e27b29c94b97b7c12d1e8a2dd886fdff'
DaozeZhang 6bbd9f7
Merge branch 'modelscope:main' into main
DaozeZhang 9ce9e9f
Merge branch 'modelscope:main' into main
DaozeZhang b7afb5e
Merge commit 'd42f8b5c3d3af7ee7ef58ff3ebdcb8ed790afb68'
DaozeZhang b22f7f3
Merge branch 'modelscope:main' into main
DaozeZhang 9ef7838
Merge commit '44302aba29a8909892322ec18dfdf7398c5cec88'
DaozeZhang 7d45ea3
Merge branch 'modelscope:main' into main
DaozeZhang e4d420e
Merge commit '53790bd87fb1327f83837a779a55d90e029101d4'
DaozeZhang a2a5c15
Merge branch 'modelscope:main' into main
DaozeZhang 3017915
Merge commit 'a2a5c15cb2da3e75d11581230e0c310d7c4f5e5b'
DaozeZhang 8926d3d
Merge commit '96eeecc6af0bf3fcfbec564eb6f5d66a8c8e0593'
DaozeZhang 3b721f6
support generation using Janus Pro
DaozeZhang 4d4037a
update comment
DaozeZhang 61d5842
change some var name, add test_gene.py
DaozeZhang eac536f
change format
DaozeZhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ class MaxLengthError(ValueError): | |
|
||
|
||
class Template(ProcessorMixin): | ||
special_tokens = ['<image>', '<video>', '<audio>', '<bbox>', '<ref-object>', '<cot-process>'] | ||
special_tokens = ['<image>', '<video>', '<audio>', '<bbox>', '<ref-object>', '<cot-process>', '<start-image>'] | ||
special_keys = ['images', 'videos', 'audios', 'objects'] | ||
|
||
image_placeholder = ['<image>'] | ||
|
@@ -173,6 +173,7 @@ def _preprocess_inputs( | |
) -> None: | ||
if self.model_meta.is_multimodal: | ||
self._replace_image_tags(inputs) | ||
self._replace_start_image_tags(inputs) | ||
images = inputs.images | ||
load_images = self.load_images or self.mode in {'vllm', 'lmdeploy'} | ||
load_images_origin = load_images | ||
|
@@ -217,6 +218,19 @@ def _replace_image_tags(inputs: StdTemplateInputs): | |
assert not inputs.images, f'images: {images}, inputs.images: {inputs.images}' | ||
inputs.images = images | ||
|
||
@staticmethod | ||
def _replace_start_image_tags(inputs: StdTemplateInputs): | ||
# compat | ||
generate_mode = False | ||
for message in inputs.messages: | ||
content = message['content'] | ||
if not isinstance(content, str): | ||
continue | ||
if content.strip().endswith('<start-image>'): | ||
generate_mode = True | ||
message['content'] = re.sub('<start-image>', '', content).strip() # remove the <start-image> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
inputs.generate_mode = generate_mode | ||
|
||
def _rlhf_encode(self, inputs: StdTemplateInputs) -> Dict[str, Any]: | ||
chosen_inputs, rejected_inputs = inputs, deepcopy(inputs) | ||
assert chosen_inputs.rejected_response is not None, f'inputs: {inputs}' | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import os | ||
|
||
import torch | ||
|
||
os.environ['CUDA_VISIBLE_DEVICES'] = '0' | ||
os.environ['SWIFT_DEBUG'] = '1' | ||
|
||
|
||
def test_deepseek_janus_pro_gene(): | ||
from swift.llm import infer_main, InferArguments | ||
args = InferArguments( | ||
# model='deepseek-ai/Janus-Pro-1B', | ||
model='/mnt/nas1/.cache/modelscope/hub/deepseek-ai/Janus-Pro-1B', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 路径 |
||
infer_backend='pt') | ||
infer_main(args) | ||
|
||
|
||
def test_emu3_gen(infer_backend): | ||
from swift.llm import infer_main, InferArguments | ||
args = InferArguments( | ||
model='BAAI/Emu3-Gen', | ||
infer_backend=infer_backend, | ||
stream=False, | ||
use_chat_template=False, | ||
top_k=2048, | ||
max_new_tokens=40960) | ||
infer_main(args) | ||
|
||
|
||
if __name__ == '__main__': | ||
# test_emu3_gen('pt') | ||
test_deepseek_janus_pro_gene() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strip()去掉吧
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个的话,用户有可能把
<start-image>
放末尾以后会再跟几个空格(比如我经常有这个习惯😂)需要考虑吗