Files
modelscope/modelscope/swift/base.py
yuze.zyz a58be34384 Add Lora/Adapter/Prompt and support for chatglm6B and chatglm2-6B
Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/12770413

* add prompt and lora

* add adapter

* add prefix

* add tests

* adapter smoke test passed

* prompt test passed

* support model id in petl

* migrate chatglm6b

* add train script for chatglm6b

* move gen_kwargs to finetune.py

* add chatglm2

* add model definination
2023-06-27 14:38:18 +08:00

32 lines
841 B
Python

from dataclasses import dataclass
@dataclass
class SwiftConfig:
pass
class Swift:
@staticmethod
def prepare_model(model, config: SwiftConfig):
"""Prepare the module and returns the new module.
Args:
model: The model to tune.
config: The config of the tuner.
Returns:
The tuned model.
"""
from .lora import LoRA, LoRAConfig
from .adapter import Adapter, AdapterConfig
from .prompt import Prompt, PromptConfig
if isinstance(config, LoRAConfig):
return LoRA.prepare_model(model, config)
elif isinstance(config, AdapterConfig):
return Adapter.prepare_model(model, config)
elif isinstance(config, PromptConfig):
return Prompt.prepare_model(model, config)
return None