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

feat(SDK): Add SemaphoreKey and MutexName fields to DSL #11340

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 36 additions & 0 deletions sdk/python/kfp/compiler/compiler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3847,6 +3847,42 @@ def outer():
foo_platform_set_bar_feature(task, 12)


class TestPipelineSemaphoreMutex(unittest.TestCase):

def test_pipeline_with_semaphore_and_mutex(self):
from kfp import compiler
from kfp import dsl
from kfp.dsl.pipeline_config import PipelineConfig

config = PipelineConfig()
config.set_semaphore_key('semaphore')
config.set_mutex_name('mutex')

@dsl.pipeline(pipeline_config=config)
def my_pipeline():
task = comp()

with tempfile.TemporaryDirectory() as tempdir:
output_yaml = os.path.join(tempdir, 'pipeline.yaml')
compiler.Compiler().compile(
pipeline_func=my_pipeline, package_path=output_yaml)

with open(output_yaml, 'r') as f:
pipeline_docs = list(yaml.safe_load_all(f))

pipeline_spec = None
for doc in pipeline_docs:
if 'platforms' in doc:
pipeline_spec = doc
break

if pipeline_spec:
kubernetes_spec = pipeline_spec['platforms']['kubernetes'][
'pipelineConfig']
assert kubernetes_spec['semaphoreKey'] == 'semaphore'
assert kubernetes_spec['mutexName'] == 'mutex'


class ExtractInputOutputDescription(unittest.TestCase):

def test_no_descriptions(self):
Expand Down
12 changes: 7 additions & 5 deletions sdk/python/kfp/compiler/pipeline_spec_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2011,11 +2011,13 @@ def write_pipeline_spec_to_file(

def _merge_pipeline_config(pipelineConfig: pipeline_config.PipelineConfig,
platformSpec: pipeline_spec_pb2.PlatformSpec):
# TODO: add pipeline config options (ttl, semaphore, etc.) to the dict
# json_format.ParseDict(
# {'pipelineConfig': {
# '<some pipeline config option>': pipelineConfig.<get that value>,
# }}, platformSpec.platforms['kubernetes'])
json_format.ParseDict(
{
'pipelineConfig': {
'semaphoreKey': pipelineConfig.semaphore_key,
'mutexName': pipelineConfig.mutex_name,
}
}, platformSpec.platforms['kubernetes'])

return platformSpec

Expand Down
19 changes: 17 additions & 2 deletions sdk/python/kfp/dsl/pipeline_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ class PipelineConfig:
"""PipelineConfig contains pipeline-level config options."""

def __init__(self):
pass
self.semaphore_key = None
self.mutex_name = None

# TODO add pipeline level configs
def set_semaphore_key(self, semaphore_key: str):
"""Set the name of the semaphore to control pipeline concurrency.

Args:
semaphore_key (str): Name of the semaphore.
"""
self.semaphore_key = semaphore_key.strip()

def set_mutex_name(self, mutex_name: str):
"""Set the name of the mutex to ensure mutual exclusion.

Args:
mutex_name (str): Name of the mutex.
"""
self.mutex_name = mutex_name.strip()
Loading