Skip to content

What's new

0.2.1

Tasks return to their earlier behavior. Job.wait() no longer creates a preempted job again. The default task bucket keeps its 0.2.0 name, ns-workspace-<project id>. Some 0.2.0 calls are removed, with no aliases.

Upgrading from 0.2.0

0.2.0 0.2.1
ns.tasks.get(run_id) Removed. Keep the TaskRun that submit() returns. Its files are at run.output_uri
task.clone(key=...).submit(...) Removed. Every submit() starts a new job
task.clone(gpu=...) Build a new ns.Task(...)
task.dry_run(...) Removed
ns.Task(..., bucket=...), ns.configure(bucket=..., prefix=...), NS_BUCKET Removed. Tasks use ns-workspace-<project id>
A GPU task runs on spot by default On-demand by default. Pass pricing="spot"
ns.Task(..., preemption_retries=N) Removed. A preempted task ends in TaskFailed. Submit it again
run.id, run.uri, run.attempts, run.result(timeout=...) Removed
restart_attempts on a task raises ValidationError Accepted. The container restarts after a failure, so the function runs again
NS_TASK_RUN, NS_TASK_ATTEMPT in the job No longer set
JobSpec(preemption_retries=N), ns.Job(..., preemption_retries=N) Removed. Passing it raises TypeError, like any unknown argument
job.wait() creates a preempted spot job again (since 0.1.0) Never. A preempted job ends in ERROR with code Preempted. Create it again: ns.Job(job.spec).create()
restart_attempts on spot also set a resubmit budget Only restarts the container after a failed command, as the API does
job.attempts, job.preemptions Removed. job.id never changes after create()

Runs made by 0.2.0 stay in the bucket, and 0.2.1 can't reattach them. See Tasks and Spot preemption.

0.2.0

0.2.0 adds tasks, images and a Prefect integration. Jobs and endpoints are built directly with ns.Job(...) and ns.Endpoint(...), and specs become plain data for YAML and reuse. A repeated call no longer starts a second paid job. Some 0.1.0 calls change, with no aliases.

Breaking changes

0.1.0 0.2.0
ns.JobSpec(["python", "x.py"], image=...) ns.Job(command=["python", "x.py"], image=...), or ns.JobSpec(command=["python", "x.py"], image=...) for a spec
spec.create() ns.Job(command=[...], ...).create(), or ns.Job(spec).create()
spec.create(dry_run=True) job.dry_run()
spec.to_cli() job.to_cli()
one spec, many create() calls one ns.Job(...).create() per job, or ns.Job(spec.clone(...)).create()
ns.EndpointSpec(...).create() ns.Endpoint(image=..., ...).create(), or ns.Endpoint(spec).create()
pricing defaults to "on-demand" On a GPU machine, pricing defaults to spot. Pass pricing="on-demand" for a machine that must not be preempted. CPU machines stay on-demand

There are no aliases and no deprecation warnings: update the calls.

# 0.1.0
job = ns.JobSpec(["nvidia-smi"], image=IMAGE, gpu="h100", timeout="10m").create()

# 0.2.0
job = ns.Job(command=["nvidia-smi"], image=IMAGE, gpu="h100", timeout="10m").create()

# 0.2.0, from a spec: for YAML and reuse
spec = ns.JobSpec(command=["nvidia-smi"], image=IMAGE, gpu="h100", timeout="10m")
job = ns.Job(spec).create()

New dependency

pydantic>=2,<3. JobSpec and EndpointSpec are Pydantic models. The Prefect integration already brings Pydantic v2.

Jobs and endpoints

  • Build directly. ns.Job(command=[...], image=..., ...) and ns.Endpoint(image=..., ...) take the parameters and create once. command is passed by name. See Jobs.
  • Specs are data. JobSpec and EndpointSpec are frozen and compare by value, with clone(**changes), to_dict(), to_yaml() and a JSON schema (model_json_schema()). See Specs are data.
  • Create once on the handle. create() on a Job or an Endpoint creates it once and returns the handle. id is None before create(). ns.Job(spec) and ns.Endpoint(spec) check the spec they get.
  • Spot by default on a GPU. Jobs, endpoints and tasks on a GPU machine run on spot unless pricing="on-demand" is set. CPU machines run on-demand. See On-demand or spot.
  • Server dry run. dry_run(server=True) asks Nebius to validate the request, and creates nothing.
  • Spot preemption. preemption_retries=N on a spot JobSpec creates a preempted job again while wait() runs. See Spot preemption.
  • Buckets by name. s3://<bucket name>:/path volumes now work: the name is looked up and the bucket is mounted by its id. A missing bucket fails before create. See Storage and files.
  • Sync calls in notebooks. create(), wait() and the other sync calls work in a Jupyter cell: inside a running event loop they run on a worker thread.

Images

  • ns.Image builds a Dockerfile on a CPU job and pushes it to the project's registry. The tag is a hash of the Dockerfile, so a built image is reused. See Images.

Tasks

  • ns.Task runs a Python function or a bash script as a job and returns its result. submit() returns a run at once, and a run can be passed to another task. See Tasks.
  • The task bucket is the project's ns-workspace-<project id>, created on the first run, or a bucket you choose with bucket=, ns.configure(bucket=...) or NS_BUCKET.
  • Reattach. A run has a stable run id. ns.tasks.get(run_id) reconnects after a kernel restart or a crash, from the run id or any attempt's job id.
  • Preemption retries. preemption_retries=N on a spot task creates a preempted job again, as another attempt of the same run. Only a confirmed preemption is retried, never a function that raised. Files in $NS_OUTPUT_DIR survive between attempts, and NS_TASK_ATTEMPT tells the job which attempt it is.
  • Notebook functions. A function defined in a notebook cell is sent as its source. The job warns when its Python version differs from yours.
  • Task dry run. task.dry_run(*args, server=False, **kwargs) shows the job a call would start, and creates nothing.
  • Caller keys. task.clone(key="...").submit(...) makes a repeated call return the existing run and start no job, also from a new process. Other arguments, or a changed task, raise KeyConflict. See Caller keys.
  • Task.clone(**changes) makes a copy with changes to any constructor argument, checked the same way.
  • Reserved variables. A task's env and secrets can't set the variables the library sets, such as NS_TASK_RUN and NS_BUCKET.

Integrations

  • Prefect. PrefectFlow runs a pipeline of tasks as a Prefect flow. Install it with pip install "nebius-serverless[prefect]". See Prefect.

Examples

  • Notebooks: a task notebook with a dry run, a caller key and a reattach after a kernel restart.
  • Agents: an image agent that starts and stops its own endpoint, and one that makes keyframe options in a task.
  • Pipeline of tasks: MNIST training as tasks, in plain Python or as a Prefect flow.