From 14aaf791da377e0e862d3dbef6db5f25e83fef69 Mon Sep 17 00:00:00 2001 From: Vladimir Lipkin Date: Fri, 6 Dec 2024 19:59:23 +0100 Subject: [PATCH] Improve tuning.list example (#38) --- examples/async/tuning/list.py | 11 +++++++---- examples/sync/tuning/list.py | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/examples/async/tuning/list.py b/examples/async/tuning/list.py index 560a07b..154f91a 100755 --- a/examples/async/tuning/list.py +++ b/examples/async/tuning/list.py @@ -52,22 +52,25 @@ async def main() -> None: base_model = sdk.models.completions('yandexgpt-lite') task_ids = set() - for _ in range(1): + for _ in range(3): tuning_task = await base_model.tune_deferred( train_dataset, validation_datasets=validation_dataset, name=str(uuid.uuid4()) ) + print(f'created task {tuning_task.id=}') task_ids.add(tuning_task.id) # NB: tuning tasks have a time gap, before they will # be available at the backend as a `TuningTasks` await asyncio.sleep(5) + print('And now - cancel all created tasks:') async for tuning_task in sdk.tuning.list(): - # or you could wait for tasks, instead of canceling - print(f'found task {tuning_task=}, canceling') - await tuning_task.cancel() + if tuning_task.id in task_ids: + # or you could wait for tasks, instead of canceling + print(f'found task {tuning_task=}, canceling') + await tuning_task.cancel() if __name__ == '__main__': diff --git a/examples/sync/tuning/list.py b/examples/sync/tuning/list.py index d5ae210..25495a3 100755 --- a/examples/sync/tuning/list.py +++ b/examples/sync/tuning/list.py @@ -52,22 +52,25 @@ def main() -> None: base_model = sdk.models.completions('yandexgpt-lite') task_ids = set() - for _ in range(1): + for _ in range(3): tuning_task = base_model.tune_deferred( train_dataset, validation_datasets=validation_dataset, name=str(uuid.uuid4()) ) + print(f'created task {tuning_task.id=}') task_ids.add(tuning_task.id) # NB: tuning tasks have a time gap, before they will # be available at the backend as a `TuningTasks` time.sleep(5) + print('And now - cancel all created tasks:') for tuning_task in sdk.tuning.list(): - # or you could wait for tasks, instead of canceling - print(f'found task {tuning_task=}, canceling') - tuning_task.cancel() + if tuning_task.id in task_ids: + # or you could wait for tasks, instead of canceling + print(f'found task {tuning_task=}, canceling') + tuning_task.cancel() if __name__ == '__main__':