Skip to content

Commit

Permalink
Improve tuning.list example (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
vhaldemar committed Dec 26, 2024
1 parent 3e8da72 commit 14aaf79
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 7 additions & 4 deletions examples/async/tuning/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down
11 changes: 7 additions & 4 deletions examples/sync/tuning/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down

0 comments on commit 14aaf79

Please sign in to comment.