Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Kubeflow Pipelines GPU Resource Request Sample

From Leeroopedia
Knowledge Sources
Domains Pipeline_Sample, Resource_Management, GPU
Last Updated 2026-02-13 14:00 GMT

Overview

Sample pipeline demonstrating GPU resource requests and accelerator type constraints for pipeline tasks using the KFP SDK.

Description

This sample (53 lines) shows how to request GPU resources. The `training_job` component uses a PyTorch CUDA base image and verifies GPU availability. The `generate_resource_constraints_request` component returns GPU count and accelerator type. GPU count can be set dynamically via `set_accelerator_limit()`, but accelerator type must be hardcoded due to SDK limitations.

Usage

Reference this sample when building GPU-enabled pipelines targeting specific hardware like NVIDIA Tesla K80.

Code Reference

Source Location

Signature

@dsl.component(base_image='pytorch/pytorch:1.7.1-cuda11.0-cudnn8-runtime')
def training_job():
    """Checks torch.cuda.is_available(), raises if no GPU."""

@dsl.component
def generate_resource_constraints_request() -> NamedTuple('Outputs', [('nbr_gpus', str), ('accelerator', str)]):
    """Returns nbr_gpus='1', accelerator='NVIDIA_TESLA_K80'."""

@dsl.pipeline
def resource_constraint_request_pipeline():
    """Pipeline: generate GPU constraints -> training job with GPU."""

Import

from kfp import dsl
from typing import NamedTuple

I/O Contract

Inputs

Name Type Required Description
(none) Pipeline takes no inputs

Outputs

Name Type Description
Compiled YAML file Pipeline IR YAML for submission to KFP

Usage Examples

GPU Pipeline Pattern

from kfp import dsl

@dsl.pipeline
def gpu_pipeline():
    constraints = generate_resource_constraints_request()
    task = training_job()
    task.set_accelerator_limit(constraints.outputs['nbr_gpus'])
    # Accelerator type must be hardcoded (SDK limitation)
    task.set_accelerator_type('NVIDIA_TESLA_K80')

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment