Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Parallel Run Step partition by keys #26844

Merged
merged 28 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class ParallelComponentSchema(ComponentSchema):
mini_batch_size = fields.Str(
bupt-wenxiaole marked this conversation as resolved.
Show resolved Hide resolved
metadata={"description": "The The batch size of current job."},
)
partition_keys = fields.List(
fields.Str(),
bupt-wenxiaole marked this conversation as resolved.
Show resolved Hide resolved
metadata={"description": "The keys used to partition input data into mini-batches"}
)

input_data = fields.Str()
retry_settings = NestedField(RetrySettingsSchema, unknown=INCLUDE)
max_concurrency_per_instance = fields.Integer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class ParameterizedParallelSchema(PathAwareSchema):
mini_batch_size = fields.Str(
metadata={"description": "The batch size of current job."},
)
partition_keys = fields.List(
fields.Str(),
metadata={"description": "The keys used to partition input data into mini-batches"}
)
input_data = fields.Str()
resources = NestedField(JobResourceConfigurationSchema)
retry_settings = NestedField(RetrySettingsSchema, unknown=INCLUDE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------
import os
from typing import Dict, Union
from typing import Dict, Union, List

from azure.ai.ml._restclient.v2022_02_01_preview.models import AmlToken, ManagedIdentity
from azure.ai.ml.constants._component import ComponentSource
Expand Down Expand Up @@ -31,6 +31,7 @@ def parallel_run_function(
mini_batch_error_threshold: int = None,
task: RunFunction = None,
mini_batch_size: str = None,
partition_keys: List = None,
input_data: str = None,
inputs: Dict = None,
outputs: Dict = None,
Expand Down Expand Up @@ -136,6 +137,12 @@ def parallel_run_function(
(optional, default value is 10 files for FileDataset and 1MB for TabularDataset.) This value could be set
through PipelineParameter.
:type mini_batch_size: str
:param partition_keys: The keys used to partition dataset into mini-batches.
bupt-wenxiaole marked this conversation as resolved.
Show resolved Hide resolved
If specified, the data with the same key will be partitioned into the same mini-batch.
If both partition_keys and mini_batch_size are specified, error would be raised.
The input(s) must be partitioned dataset(s),
and the partition_keys must be a subset of the keys of every input dataset for this to work.
:type partition_keys: List
:param input_data: The input data.
:type input_data: str
:param inputs: a dict of inputs used by this parallel.
Expand Down Expand Up @@ -190,6 +197,7 @@ def parallel_run_function(
mini_batch_error_threshold=mini_batch_error_threshold,
task=task,
mini_batch_size=mini_batch_size,
partition_keys=partition_keys,
input_data=input_data,
_source=ComponentSource.BUILDER,
is_deterministic=is_deterministic,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import os
import re
from typing import Any, Dict, Union
from typing import Any, Dict, Union, List

from marshmallow import Schema

Expand Down Expand Up @@ -53,6 +53,12 @@ class ParallelComponent(Component, ParameterizedParallel): # pylint: disable=to
(optional, default value is 10 files for FileDataset and 1MB for TabularDataset.) This value could be set
through PipelineParameter.
:type mini_batch_size: str
:param partition_keys: The keys used to partition dataset into mini-batches.
If specified, the data with the same key will be partitioned into the same mini-batch.
If both partition_keys and mini_batch_size are specified, error would be raised.
The input(s) must be partitioned dataset(s),
and the partition_keys must be a subset of the keys of every input dataset for this to work.
:type partition_keys: list
:param input_data: The input data.
:type input_data: str
:param resources: Compute Resource configuration for the component.
Expand Down Expand Up @@ -86,6 +92,7 @@ def __init__(
mini_batch_error_threshold: int = None,
task: ParallelTask = None,
mini_batch_size: str = None,
partition_keys: List = None,
bupt-wenxiaole marked this conversation as resolved.
Show resolved Hide resolved
input_data: str = None,
resources: JobResourceConfiguration = None,
inputs: Dict = None,
Expand Down Expand Up @@ -116,6 +123,7 @@ def __init__(
# and fill in later with job defaults.
self.task = task
self.mini_batch_size = mini_batch_size
self.partition_keys = partition_keys
self.input_data = input_data
self.retry_settings = retry_settings
self.logging_level = logging_level
Expand All @@ -136,6 +144,14 @@ def __init__(
self.instance_count = instance_count
self.code = code

if self.mini_batch_size is not None and self.partition_keys is not None:
msg = "mini_batch_size and partition_keys are mutually exclusive"
raise ValidationException(
message=msg,
target=ErrorTarget.COMPONENT,
no_personal_data_message=msg,
error_category=ErrorCategory.USER_ERROR,
)
if self.mini_batch_size is not None:
# Convert str to int.
pattern = re.compile(r"^\d+([kKmMgG][bB])*$")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class ParallelJob(Job, ParameterizedParallel, JobIOMixin):
:type task: ParallelTask
:param mini_batch_size: The mini batch size.
:type mini_batch_size: str
:param partition_keys: The partition keys.
:type partition_keys: list
:param input_data: The input data.
:type input_data: str
:param inputs: Inputs of the job.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# ---------------------------------------------------------

import logging
from typing import Dict, Union
from typing import Dict, Union, List

from ..job_resource_configuration import JobResourceConfiguration
from .parallel_task import ParallelTask
Expand Down Expand Up @@ -47,10 +47,12 @@ def __init__(
input_data: str = None,
task: ParallelTask = None,
mini_batch_size: int = None,
partition_keys: List = None,
resources: Union[dict, JobResourceConfiguration] = None,
environment_variables: Dict = None,
):
self.mini_batch_size = mini_batch_size
self.partition_keys = partition_keys
self.task = task
self.retry_settings = retry_settings
self.input_data = input_data
Expand Down