Swift
- class swift.tuners.base.Swift[源代码]
The Wrapper to use both Peft and Swift tuners.
- static prepare_model(model, config, **kwargs)[源代码]
Prepare a model by the input config.
- 参数:
model (Union[nn.Module, 'SwiftModel']) -- The model to be tuned.
config (Union[SwiftConfig, PeftConfig, Dict[str, SwiftConfig]]) -- The config or config dict, can be either SwiftConfigs or PeftConfigs
**kwargs -- Extra kwargs needed by SwiftModel or PeftModel.
- 返回:
The model wrapped by SwiftModel or PeftModel.
- static merge_and_unload(model, **kwargs)[源代码]
Merge tuners into the base model and unload them.
- 参数:
model (Union[PeftModel, SwiftModel]) -- The model instance with tuners
kwargs -- adapter_name(Union[str, List[str]]): The adapter_name to unload, only supported in swift tuners.
- static merge(model, **kwargs)[源代码]
Merge tuners into the base model, will not unload them.
- 参数:
model (Union[PeftModel, SwiftModel]) -- The model instance with tuners
- static unmerge(model, **kwargs)[源代码]
Unmerge tuners from the base model
- 参数:
model (Union[PeftModel, SwiftModel]) -- The model instance with tuners
- static save_to_peft_format(ckpt_dir, output_dir)[源代码]
Save swift format to peft format
- 参数:
ckpt_dir (str) -- Original swift output dir
output_dir (str) -- Converted peft format dir
- static from_pretrained(model, model_id=None, adapter_name=None, revision=None, **kwargs)[源代码]
Prepare a model by a model_id in the ModelScope hub or a local dir.
- 参数:
model (Union[nn.Module, 'SwiftModel']) -- The model to be tuned.
model_id (str) -- The model id of the modelhub or a local dir containing the configs/weights.
adapter_name (str, optional) -- The adapter_name to use.
revision (str, optional) -- The model revision if the model_id is a model id of the modelhub.
**kwargs -- Extra kwargs needed by
SwiftModel.from_pretrainedorPeftModel.from_pretrained.
- 返回:
The model wrapped by SwiftModel or PeftModel.