Skip to content

Commit

Permalink
component changes for phi 3.5 (#3372)
Browse files Browse the repository at this point in the history
* component changes for phi 3.5

* component changes for phi 3.5

* component changes for phi 3.5

* component changes for phi 3.5

---------

Co-authored-by: Anubha Jain <[email protected]>
  • Loading branch information
Anubha98 and Anubha Jain authored Sep 16, 2024
1 parent b940da8 commit 888348a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions assets/training/finetune_acft_hf_nlp/src/finetune/finetune.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,16 @@ def finetune(args: Namespace):
shutil.copy(str(conda_file_path), args.output_dir)
logger.info(f"Copied {MLFlowHFFlavourConstants.CONDA_YAML_FILE} file to output dir.")

# copy inference config files
mlflow_ml_configs_dir = Path(args.model_selector_output, "ml_configs")
ml_config_dir = Path(args.output_dir, "ml_configs")
if mlflow_ml_configs_dir.is_dir():
shutil.copytree(
mlflow_ml_configs_dir,
ml_config_dir
)
logger.info("Copied ml_configs folder to output dir.")


def can_apply_ort(args: Namespace, logger):
"""Can ORT be enabled."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ def copy_finetune_config(self, src_model_path: str, dst_model_path: str):
)
logger.info(f"Copied {SaveFileConstants.ACFT_CONFIG_SAVE_PATH} file.")

def copy_ml_configs(self, src_model_path: str, dst_model_path: str):
"""Copy ml_configs folder to mlflow model artifacts."""
ml_configs_path = Path(src_model_path, "ml_configs")
dst_model_path = Path(dst_model_path, "ml_configs")
if ml_configs_path.is_dir():
shutil.copytree(
ml_configs_path,
dst_model_path
)
logger.info("Copied ml_configs folder.")


class PyTorch_to_MlFlow_ModelConverter:
"""Mixin class to convert pytorch to hftransformers/oss flavour mlflow model."""
Expand Down Expand Up @@ -224,6 +235,7 @@ def convert_model(self) -> None:
self.download_license_file(self.model_name, self.ft_pytorch_model_path, self.mlflow_model_save_path)
self.add_model_signature()
self.copy_finetune_config(self.ft_pytorch_model_path, self.mlflow_model_save_path)
self.copy_ml_configs(self.ft_pytorch_model_path, self.mlflow_model_save_path)
copy_tokenizer_files_to_model_folder(self.mlflow_model_save_path, self.component_args.task_name)

logger.info("Saved MLFlow model using HFTransformers flavour.")
Expand Down Expand Up @@ -315,6 +327,7 @@ def convert_model(self) -> None:
self.download_license_file(self.model_name, self.ft_pytorch_model_path, self.mlflow_model_save_path)
self.add_model_signature()
self.copy_finetune_config(self.ft_pytorch_model_path, self.mlflow_model_save_path)
self.copy_ml_configs(self.ft_pytorch_model_path, self.mlflow_model_save_path)

# Temp fix for t5 text-classification, translation, summarization
if self.is_t5_finetune(model.config.model_type):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,16 @@ def main():
shutil.copy(str(conda_file_path), args.output_dir)
logger.info(f"Copied {MLFlowHFFlavourConstants.CONDA_YAML_FILE} file to output dir.")

# copy inference config files
mlflow_ml_configs_dir = Path(args.mlflow_model_path, "ml_configs")
ml_config_dir = Path(args.output_dir, "ml_configs")
if mlflow_ml_configs_dir.is_dir():
shutil.copytree(
mlflow_ml_configs_dir,
ml_config_dir
)
logger.info("Copied ml_configs folder to output dir.")


if __name__ == "__main__":
main()

0 comments on commit 888348a

Please sign in to comment.