diff --git a/.github/workflows/publish-core-images.yaml b/.github/workflows/publish-core-images.yaml index d24d384cb6..b81185071d 100644 --- a/.github/workflows/publish-core-images.yaml +++ b/.github/workflows/publish-core-images.yaml @@ -24,3 +24,6 @@ jobs: dockerfile: build/images/training-operator/Dockerfile - component-name: kubectl-delivery dockerfile: build/images/kubectl-delivery/Dockerfile + - component-name: storage-initializer + dockerfile: sdk/python/kubeflow/storage_initializer/Dockerfile + context: sdk/python/kubeflow/storage_initializer \ No newline at end of file diff --git a/sdk/python/kubeflow/storage_init_container/constants.py b/sdk/python/kubeflow/storage_init_container/constants.py deleted file mode 100644 index 1a2af2196d..0000000000 --- a/sdk/python/kubeflow/storage_init_container/constants.py +++ /dev/null @@ -1 +0,0 @@ -INIT_CONTAINER_MOUNT_PATH = "/workspace" diff --git a/sdk/python/kubeflow/storage_init_container/Dockerfile b/sdk/python/kubeflow/storage_initializer/Dockerfile similarity index 82% rename from sdk/python/kubeflow/storage_init_container/Dockerfile rename to sdk/python/kubeflow/storage_initializer/Dockerfile index 984f3ec5a7..558e3553da 100644 --- a/sdk/python/kubeflow/storage_init_container/Dockerfile +++ b/sdk/python/kubeflow/storage_initializer/Dockerfile @@ -5,7 +5,7 @@ FROM python:3.11 WORKDIR /app # Copy the Python package and its source code into the container -COPY . /app/storage_init_container +COPY . /app/storage_initializer # Copy the requirements.txt file into the container COPY requirements.txt /app/requirements.txt @@ -14,4 +14,4 @@ COPY requirements.txt /app/requirements.txt RUN pip install --no-cache-dir -r requirements.txt # Run storage.py when the container launches -ENTRYPOINT ["python", "-m", "storage_init_container.storage"] +ENTRYPOINT ["python", "-m", "storage_initializer.storage"] diff --git a/sdk/python/kubeflow/storage_init_container/__init__.py b/sdk/python/kubeflow/storage_initializer/__init__.py similarity index 100% rename from sdk/python/kubeflow/storage_init_container/__init__.py rename to sdk/python/kubeflow/storage_initializer/__init__.py diff --git a/sdk/python/kubeflow/storage_init_container/abstract_dataset_provider.py b/sdk/python/kubeflow/storage_initializer/abstract_dataset_provider.py similarity index 100% rename from sdk/python/kubeflow/storage_init_container/abstract_dataset_provider.py rename to sdk/python/kubeflow/storage_initializer/abstract_dataset_provider.py diff --git a/sdk/python/kubeflow/storage_init_container/abstract_model_provider.py b/sdk/python/kubeflow/storage_initializer/abstract_model_provider.py similarity index 100% rename from sdk/python/kubeflow/storage_init_container/abstract_model_provider.py rename to sdk/python/kubeflow/storage_initializer/abstract_model_provider.py diff --git a/sdk/python/kubeflow/storage_initializer/constants.py b/sdk/python/kubeflow/storage_initializer/constants.py new file mode 100644 index 0000000000..19b36523de --- /dev/null +++ b/sdk/python/kubeflow/storage_initializer/constants.py @@ -0,0 +1,3 @@ +INIT_CONTAINER_MOUNT_PATH = "/workspace" +VOLUME_PATH_DATASET = INIT_CONTAINER_MOUNT_PATH + "/dataset" +VOLUME_PATH_MODEL = INIT_CONTAINER_MOUNT_PATH + "/model" diff --git a/sdk/python/kubeflow/storage_init_container/hugging_face.py b/sdk/python/kubeflow/storage_initializer/hugging_face.py similarity index 75% rename from sdk/python/kubeflow/storage_init_container/hugging_face.py rename to sdk/python/kubeflow/storage_initializer/hugging_face.py index 9f42c10a4b..06fb3f5b50 100644 --- a/sdk/python/kubeflow/storage_init_container/hugging_face.py +++ b/sdk/python/kubeflow/storage_initializer/hugging_face.py @@ -4,7 +4,7 @@ from urllib.parse import urlparse import json, os from typing import Union -from .constants import INIT_CONTAINER_MOUNT_PATH +from .constants import VOLUME_PATH_DATASET, VOLUME_PATH_MODEL from .abstract_model_provider import modelProvider from .abstract_dataset_provider import datasetProvider @@ -24,21 +24,12 @@ class HuggingFaceModelParams: model_uri: str transformer_type: TRANSFORMER_TYPES access_token: str = None - download_dir: str = field(default=os.path.join(INIT_CONTAINER_MOUNT_PATH, "models")) def __post_init__(self): # Custom checks or validations can be added here if self.model_uri == "" or self.model_uri is None: raise ValueError("model_uri cannot be empty.") - @property - def download_dir(self): - return self.download_dir - - @download_dir.setter - def download_dir(self, value): - raise AttributeError("Cannot modify read-only field 'download_dir'") - @dataclass class HuggingFaceTrainParams: @@ -62,11 +53,11 @@ def download_model_and_tokenizer(self): transformer_type_class.from_pretrained( self.model, token=self.config.access_token, - cache_dir=self.config.download_dir, + cache_dir=VOLUME_PATH_MODEL, trust_remote_code=True, ) transformers.AutoTokenizer.from_pretrained( - self.model, cache_dir=self.config.download_dir + self.model, cache_dir=VOLUME_PATH_MODEL ) @@ -74,23 +65,12 @@ def download_model_and_tokenizer(self): class HfDatasetParams: repo_id: str access_token: str = None - download_dir: str = field( - default=os.path.join(INIT_CONTAINER_MOUNT_PATH, "datasets") - ) def __post_init__(self): # Custom checks or validations can be added here if self.repo_id == "" or self.repo_id is None: raise ValueError("repo_id is None") - @property - def download_dir(self): - return self.download_dir - - @download_dir.setter - def download_dir(self, value): - raise AttributeError("Cannot modify read-only field 'download_dir'") - class HuggingFaceDataset(datasetProvider): def load_config(self, serialised_args): @@ -104,4 +84,4 @@ def download_dataset(self): if self.config.access_token: huggingface_hub.login(self.config.access_token) - load_dataset(self.config.repo_id, cache_dir=self.config.download_dir) + load_dataset(self.config.repo_id, cache_dir=VOLUME_PATH_DATASET) diff --git a/sdk/python/kubeflow/storage_init_container/requirements.txt b/sdk/python/kubeflow/storage_initializer/requirements.txt similarity index 100% rename from sdk/python/kubeflow/storage_init_container/requirements.txt rename to sdk/python/kubeflow/storage_initializer/requirements.txt diff --git a/sdk/python/kubeflow/storage_init_container/s3.py b/sdk/python/kubeflow/storage_initializer/s3.py similarity index 75% rename from sdk/python/kubeflow/storage_init_container/s3.py rename to sdk/python/kubeflow/storage_initializer/s3.py index 2a322c70ee..816f775242 100644 --- a/sdk/python/kubeflow/storage_init_container/s3.py +++ b/sdk/python/kubeflow/storage_initializer/s3.py @@ -3,7 +3,7 @@ import boto3 from urllib.parse import urlparse from .abstract_dataset_provider import datasetProvider -from .constants import INIT_CONTAINER_MOUNT_PATH +from .constants import VOLUME_PATH_DATASET @dataclass @@ -14,9 +14,6 @@ class S3DatasetParams: region_name: str = None access_key: str = None secret_key: str = None - download_dir: str = field( - default=os.path.join(INIT_CONTAINER_MOUNT_PATH, "datasets") - ) def is_valid_url(self, url): try: @@ -36,14 +33,6 @@ def __post_init__(self): raise ValueError("bucket_name or endpoint_url or file_key is None") self.is_valid_url(self.endpoint_url) - @property - def download_dir(self): - return self.download_dir - - @download_dir.setter - def download_dir(self, value): - raise AttributeError("Cannot modify read-only field 'download_dir'") - class S3(datasetProvider): def load_config(self, serialised_args): @@ -63,6 +52,6 @@ def download_dataset(self): s3_client.download_file( self.config.bucket_name, self.config.file_key, - os.path.join(self.config.download_dir, self.config.file_key), + os.path.join(VOLUME_PATH_DATASET, self.config.file_key), ) - print(f"File downloaded to: {self.config.download_dir}") + print(f"File downloaded to: {VOLUME_PATH_DATASET}") diff --git a/sdk/python/kubeflow/storage_init_container/storage.py b/sdk/python/kubeflow/storage_initializer/storage.py similarity index 100% rename from sdk/python/kubeflow/storage_init_container/storage.py rename to sdk/python/kubeflow/storage_initializer/storage.py diff --git a/sdk/python/kubeflow/training/api/training_client.py b/sdk/python/kubeflow/training/api/training_client.py index 6eb80f0192..f0997eddff 100644 --- a/sdk/python/kubeflow/training/api/training_client.py +++ b/sdk/python/kubeflow/training/api/training_client.py @@ -24,7 +24,11 @@ from kubeflow.training.api_client import ApiClient from kubeflow.training.constants import constants from kubeflow.training.utils import utils -from kubeflow.storage_init_container.constants import INIT_CONTAINER_MOUNT_PATH +from kubeflow.storage_initializer.constants import ( + INIT_CONTAINER_MOUNT_PATH, + VOLUME_PATH_DATASET, + VOLUME_PATH_MODEL, +) logger = logging.getLogger(__name__) @@ -116,8 +120,8 @@ def train( print( "train api dependencies not installed. Run pip install -U 'kubeflow-training[huggingface]' " ) - from kubeflow.storage_init_container.s3 import S3DatasetParams - from kubeflow.storage_init_container.hugging_face import ( + from kubeflow.storage_initializer.s3 import S3DatasetParams + from kubeflow.storage_initializer.hugging_face import ( HuggingFaceModelParams, HuggingFaceTrainParams, HfDatasetParams, @@ -209,9 +213,9 @@ def train( "--transformer_type", model_provider_parameters.transformer_type.__class__.__name__, "--model_dir", - model_provider_parameters.download_dir, + VOLUME_PATH_MODEL, "--dataset_dir", - dataset_provider_parameters.download_dir, + VOLUME_PATH_DATASET, "--dataset_name", dataset_provider_parameters.repo_id, "--lora_config", @@ -222,7 +226,7 @@ def train( volume_mounts=[ models.V1VolumeMount( name=constants.TRAINER_PV, - mount_path=constants.TRAINER_CONTAINER_MOUNT_PATH, + mount_path=INIT_CONTAINER_MOUNT_PATH, ) ], resources=resources_per_worker, diff --git a/sdk/python/kubeflow/training/constants/constants.py b/sdk/python/kubeflow/training/constants/constants.py index 0219c1bd2b..63e32085da 100644 --- a/sdk/python/kubeflow/training/constants/constants.py +++ b/sdk/python/kubeflow/training/constants/constants.py @@ -168,5 +168,3 @@ models.KubeflowOrgV1MPIJob, models.KubeflowOrgV1PaddleJob, ] - -TRAINER_CONTAINER_MOUNT_PATH = "/workspace"