2023-04-11 22:26:13 +08:00
|
|
|
# Copyright 2022-2023 The Alibaba Fundamental Vision Team Authors. All rights reserved.
|
2023-09-18 18:22:53 +08:00
|
|
|
import os
|
2023-04-11 22:26:13 +08:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
from modelscope.models import Model
|
|
|
|
|
from modelscope.pipelines import pipeline
|
|
|
|
|
from modelscope.utils.constant import Tasks
|
|
|
|
|
from modelscope.utils.test_utils import test_level
|
|
|
|
|
|
|
|
|
|
|
2023-05-14 23:41:40 +08:00
|
|
|
class EfficientDiffusionTuningTest(unittest.TestCase):
|
2023-04-11 22:26:13 +08:00
|
|
|
|
|
|
|
|
def setUp(self) -> None:
|
2024-12-05 20:07:32 +08:00
|
|
|
# os.system('pip install ms-swift -U')
|
2023-04-11 22:26:13 +08:00
|
|
|
self.task = Tasks.efficient_diffusion_tuning
|
|
|
|
|
|
2024-12-05 20:07:32 +08:00
|
|
|
@unittest.skip
|
2023-04-11 22:26:13 +08:00
|
|
|
def test_efficient_diffusion_tuning_lora_run_pipeline(self):
|
|
|
|
|
model_id = 'damo/multi-modal_efficient-diffusion-tuning-lora'
|
2023-08-18 20:30:04 +08:00
|
|
|
model_revision = 'v1.0.2'
|
2023-04-11 22:26:13 +08:00
|
|
|
inputs = {'prompt': 'pale golden rod circle with old lace background'}
|
2023-08-18 20:30:04 +08:00
|
|
|
edt_pipeline = pipeline(
|
|
|
|
|
self.task, model_id, model_revision=model_revision)
|
2023-04-11 22:26:13 +08:00
|
|
|
result = edt_pipeline(inputs)
|
|
|
|
|
print(f'Efficient-diffusion-tuning-lora output: {result}.')
|
|
|
|
|
|
2024-12-05 20:07:32 +08:00
|
|
|
@unittest.skip
|
2023-04-11 22:26:13 +08:00
|
|
|
def test_efficient_diffusion_tuning_lora_load_model_from_pretrained(self):
|
|
|
|
|
model_id = 'damo/multi-modal_efficient-diffusion-tuning-lora'
|
2023-08-18 20:30:04 +08:00
|
|
|
model_revision = 'v1.0.2'
|
|
|
|
|
model = Model.from_pretrained(model_id, model_revision=model_revision)
|
2023-09-18 18:22:53 +08:00
|
|
|
from modelscope.models.multi_modal import EfficientStableDiffusion
|
2023-04-11 22:26:13 +08:00
|
|
|
self.assertTrue(model.__class__ == EfficientStableDiffusion)
|
|
|
|
|
|
2024-12-05 20:07:32 +08:00
|
|
|
@unittest.skip
|
2023-04-11 22:26:13 +08:00
|
|
|
def test_efficient_diffusion_tuning_control_lora_run_pipeline(self):
|
2023-05-14 23:41:40 +08:00
|
|
|
# TODO: to be fixed in the future
|
2023-04-11 22:26:13 +08:00
|
|
|
model_id = 'damo/multi-modal_efficient-diffusion-tuning-control-lora'
|
2023-08-18 20:30:04 +08:00
|
|
|
model_revision = 'v1.0.2'
|
2023-04-11 22:26:13 +08:00
|
|
|
inputs = {
|
|
|
|
|
'prompt':
|
|
|
|
|
'pale golden rod circle with old lace background',
|
|
|
|
|
'cond':
|
|
|
|
|
'data/test/images/efficient_diffusion_tuning_sd_control_lora_source.png'
|
|
|
|
|
}
|
2023-08-18 20:30:04 +08:00
|
|
|
edt_pipeline = pipeline(
|
|
|
|
|
self.task, model_id, model_revision=model_revision)
|
2023-04-11 22:26:13 +08:00
|
|
|
result = edt_pipeline(inputs)
|
|
|
|
|
print(f'Efficient-diffusion-tuning-control-lora output: {result}.')
|
|
|
|
|
|
2024-12-05 20:07:32 +08:00
|
|
|
@unittest.skip
|
2023-04-11 22:26:13 +08:00
|
|
|
def test_efficient_diffusion_tuning_control_lora_load_model_from_pretrained(
|
|
|
|
|
self):
|
|
|
|
|
model_id = 'damo/multi-modal_efficient-diffusion-tuning-control-lora'
|
2023-08-18 20:30:04 +08:00
|
|
|
model_revision = 'v1.0.2'
|
|
|
|
|
model = Model.from_pretrained(model_id, model_revision=model_revision)
|
2023-09-18 18:22:53 +08:00
|
|
|
from modelscope.models.multi_modal import EfficientStableDiffusion
|
2023-04-11 22:26:13 +08:00
|
|
|
self.assertTrue(model.__class__ == EfficientStableDiffusion)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|