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
f6be6d17
Commit
f6be6d17
authored
May 20, 2026
by
raojy
💬
Browse files
Update run_Transformers_imgedit.py
parent
9370f444
Pipeline
#3642
canceled with stages
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
0 deletions
+32
-0
run_Transformers_imgedit.py
run_Transformers_imgedit.py
+32
-0
No files found.
run_Transformers_imgedit.py
View file @
f6be6d17
import
torch
from
modelscope
import
AutoModelForCausalLM
,
AutoTokenizer
from
encoder.image_tokenizer
import
ImageTokenizer
from
decoder.utils
import
generate_crop_size_list
,
var_center_crop
from
decoder
import
decode_vq_tokens
from
PIL
import
Image
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 source image
image_tokenizer
=
ImageTokenizer
(
model_path
=
model_path
,
device
=
"cuda"
)
crop_size_list
=
generate_crop_size_list
((
512
//
32
)
**
2
,
32
)
pil_image
=
var_center_crop
(
Image
.
open
(
"./assets/edit_example.png"
).
convert
(
"RGB"
),
crop_size_list
=
crop_size_list
)
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"
]
# Edit the image
result
=
model
.
edit_image
(
image_tokens
,
h
,
w
,
instruction
=
"Change the background to a beach."
,
steps
=
8
,
cfg_text_scale
=
4.0
,
)
# Decode to PIL image
edited_image
=
decode_vq_tokens
(
result
[
"token_ids"
],
result
[
"h"
],
result
[
"w"
],
model_path
,
"cuda"
,
num_steps
=
8
,
decode_mode
=
"decoder-turbo"
,)
edited_image
.
save
(
"edited.png"
)
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