Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ModelZoo
LLaDA2.0-Uni
Commits
3ad22654
Commit
3ad22654
authored
May 20, 2026
by
raojy
💬
Browse files
Update run_Transformers_imgunderstand.py
parent
f6be6d17
Pipeline
#3643
failed with stages
in 0 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
0 deletions
+26
-0
run_Transformers_imgunderstand.py
run_Transformers_imgunderstand.py
+26
-0
No files found.
run_Transformers_imgunderstand.py
View file @
3ad22654
import
torch
from
modelscope
import
AutoModelForCausalLM
,
AutoTokenizer
from
encoder.image_tokenizer
import
ImageTokenizer
from
decoder.smart_img_process
import
smart_resize_images
model_path
=
"inclusionAI/LLaDA2.0-Uni"
tokenizer
=
AutoTokenizer
.
from_pretrained
(
model_path
,
trust_remote_code
=
True
)
model
=
AutoModelForCausalLM
.
from_pretrained
(
model_path
,
device_map
=
"cuda"
,
torch_dtype
=
"bfloat16"
,
trust_remote_code
=
True
).
eval
()
model
.
tokenizer
=
tokenizer
# Encode image to discrete tokens
image_tokenizer
=
ImageTokenizer
(
model_path
=
model_path
,
device
=
"cuda"
)
pil_image
=
smart_resize_images
([
"./assets/understanding_example.png"
])[
0
]
info
=
image_tokenizer
.
encode_with_info
(
pil_image
)
image_tokens
=
[
x
+
model
.
config
.
image_token_offset
for
x
in
info
[
"token_ids"
]]
_
,
h
,
w
=
info
[
"grid_thw"
]
# Understand the image
response
=
model
.
understand_image
(
image_tokens
,
h
,
w
,
question
=
"Describe this image in detail."
,
steps
=
32
,
gen_length
=
2048
,
)
print
(
response
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment