mirror of
https://github.com/modelscope/modelscope.git
synced 2025-12-16 08:17:45 +01:00
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
32 lines
841 B
Python
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
|