Skip to content

Commit faa35f0

Browse files
committed
Add --gpu to set machine_shape for push
1 parent a4351f4 commit faa35f0

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/kaggle/api/kaggle_api_extended.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3038,7 +3038,9 @@ def kernels_initialize_cli(self, folder=None):
30383038
meta_file = self.kernels_initialize(folder)
30393039
print("Kernel metadata template written to: " + meta_file)
30403040

3041-
def kernels_push(self, folder: str, timeout: Optional[str] = None) -> ApiSaveKernelResponse:
3041+
def kernels_push(
3042+
self, folder: str, timeout: Optional[str] = None, gpu: Optional[str] = None
3043+
) -> ApiSaveKernelResponse:
30423044
"""Pushes a kernel to Kaggle.
30433045
30443046
This method reads the metadata file and kernel files from a notebook,
@@ -3047,6 +3049,8 @@ def kernels_push(self, folder: str, timeout: Optional[str] = None) -> ApiSaveKer
30473049
Args:
30483050
folder (str): The path to the folder.
30493051
timeout (Optional[str]): The maximum run time in seconds.
3052+
gpu (Optional[str]): The type of GPU to use for the kernel run. If set, this value overrides boolean
3053+
settings for GPU/TPU found int metadata.
30503054
30513055
Returns:
30523056
ApiSaveKernelResponse: An ApiSaveKernelResponse object.
@@ -3165,6 +3169,9 @@ def kernels_push(self, folder: str, timeout: Optional[str] = None) -> ApiSaveKer
31653169
request.docker_image = self.get_or_default(meta_data, "docker_image", None)
31663170
if timeout:
31673171
request.session_timeout_seconds = int(timeout)
3172+
if gpu:
3173+
# The allowed names are in an enum that is not currently included in kagglesdk.
3174+
request.machine_shape = gpu
31683175
# Without the type hint, mypy thinks save_kernel() has type Any when checking warn_return_any.
31693176
response: ApiSaveKernelResponse = kaggle.kernels.kernels_api_client.save_kernel(request)
31703177
return response

src/kaggle/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ def parse_kernels(subparsers) -> None:
550550
parser_kernels_push_optional.add_argument(
551551
"-t", "--timeout", type=int, dest="timeout", help=Help.param_kernel_timeout
552552
)
553+
parser_kernels_push_optional.add_argument("--gpu", dest="gpu", help=Help.param_kernel_gpu)
553554
parser_kernels_push._action_groups.append(parser_kernels_push_optional)
554555
parser_kernels_push.set_defaults(func=api.kernels_push_cli)
555556

@@ -1299,6 +1300,7 @@ class Help(object):
12991300
param_kernel_output_file_pattern = (
13001301
"Regex pattern to match against filenames. Only files matching the pattern will be downloaded."
13011302
)
1303+
param_kernel_gpu = "Specify the type of GPU to use for the kernel run"
13021304

13031305
# Models params
13041306
param_model = "Model URL suffix in format <owner>/<model-name>"

0 commit comments

Comments
 (0)