Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/general-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
else
export DACE_optimizer_automatic_simplification=${{ matrix.simplify }}
fi
uv run --group testing pytest -n auto --cov-report=xml --cov=dace --tb=short --timeout_method thread --timeout=300 -m "not gpu and not autodiff and not torch and not onnx and not tensorflow and not mkl and not sve and not papi and not mlir and not lapack and not mpi and not scalapack and not datainstrument and not long and not sequential"
uv run --group testing pytest -n auto --cov-report=xml --cov=dace --tb=short --timeout_method thread --timeout=300 -m "not gpu and not autodiff and not torch and not onnx and not tensorflow and not mkl and not sve and not papi and not mlir and not lapack and not mpi and not scalapack and not datainstrument and not long and not sequential and not ai"
./codecov

- name: Test OpenBLAS LAPACK
Expand Down
134 changes: 134 additions & 0 deletions dace/config_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,140 @@ required:
default_Darwin: ''
default_Windows: ''

ai:
type: dict
title: AI-generated code
description: >
Preferences for the "ai" library node implementation, which expands a library node
into a tasklet written by a language model.
required:
provider:
type: str
default: 'anthropic'
title: Model provider
description: >
Which backend to generate code with. "anthropic" uses the Anthropic Messages
API (pip install 'dace[ai-anthropic]'); "responses" uses the Responses API of
the openai package (pip install 'dace[ai-openai]'); "manual" prints the prompt and
reads the reply back from the terminal, needing neither a key nor an SDK. The
SDK is only imported when an expansion actually runs.

manual_dir:
type: str
default: ''
title: Manual provider directory
description: >
Directory the "manual" provider writes prompts to and reads replies from.
Defaults to a "dace_ai_prompts" directory under the system temporary directory
when empty.

api_key_envvar:
type: str
default: 'ANTHROPIC_API_KEY'
title: API key environment variable
description: >
Name of the environment variable holding the provider's API key. If
the variable is unset, the provider's own credential chain is used instead.

model:
type: str
default: 'claude-opus-5'
title: Model
description: Identifier of the model used to generate tasklets.

effort:
type: str
default: 'high'
title: Reasoning effort
description: >
How much effort the model should spend per expansion, for providers that
support it (low, medium, high, xhigh, max).

max_tokens:
type: int
default: 64000
title: Maximum response tokens
description: Upper bound on the length of a single generated response.

timeout:
type: int
default: 600
title: Request timeout
description: Timeout, in seconds, for one request to the model provider.

verify:
type: bool
default: true
title: Verify generated code
description: >
Compile the generated tasklet in isolation before it is inserted into the
SDFG, and send any compiler diagnostics back to the model. This catches
syntax and type errors; it does not check that the result is correct.

max_repair_attempts:
type: int
default: 2
title: Maximum repair attempts
description: >
How many times the model may be asked to fix generated code that does not
compile. Only used when verification is enabled.

environment_dir:
type: str
default: ''
title: Generated environment directory
description: >
Directory where library environments requested by the model are written as
Python modules, so that they can be inspected, edited, and resolved again in
later sessions. Defaults to ~/.dace/ai_environments when empty.

cache:
type: bool
default: true
title: Reuse model answers
description: >
Store every answer on disk, keyed by the provider, the model, the effort
setting and the whole conversation, and reuse it when the same question is
asked again. Re-expanding an unchanged library node then costs nothing. Any
change to the SDFG, the node, or the model changes the key and misses the
cache, so a stale answer cannot be picked up.

cache_dir:
type: str
default: ''
title: Answer cache directory
description: >
Where reusable answers are stored. Defaults to ~/.dace/ai_cache when empty.
Deleting the directory, or any file in it, only forces the question to be
asked again.

transcripts:
type: bool
default: true
title: Record expansion transcripts
description: >
Write the prompts, the model's answers, and the source and diagnostics of every
probe compilation to disk, one directory per expansion. An expansion is a paid
and non-reproducible call whose result is baked into the SDFG, so the material
that produced it is kept by default. Set DACE_debugprint=verbose to see the
same material on the terminal as it happens.

transcript_dir:
type: str
default: ''
title: Transcript directory
description: >
Where expansion transcripts are written. Defaults to ~/.dace/ai_transcripts
when empty.

extra_instructions:
type: str
default: ''
title: Extra prompt instructions
description: >
Additional text appended to every code generation prompt, e.g. project-wide
coding conventions or libraries that should be preferred.

instrumentation:
type: dict
title: Instrumentation
Expand Down
32 changes: 32 additions & 0 deletions dace/libraries/ai/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2019-2026 ETH Zurich and the DaCe authors. All rights reserved.
"""
AI-generated implementations for DaCe library nodes.

This library provides two things:

1. The reserved ``'ai'`` implementation, available on **every** library node -- including ones
defined outside DaCe. Expanding with it asks a language model to write the replacement tasklet,
given the node's context in the SDFG and on the local machine. See
:mod:`dace.libraries.ai.expansion`.
2. :class:`~dace.libraries.ai.nodes.ai_node.AINode`, a library node that carries only a
natural-language description, for microkernels that have no library node of their own.

The model is reached through a provider selected by the ``ai.provider`` configuration entry; its
SDK is imported lazily, so nothing here requires one to be installed until an expansion actually
runs.
"""

from dace.library import register_library
from dace.sdfg.nodes import AI_IMPLEMENTATION_NAME

from .expansion import ExpandAI
from .exceptions import AIExpansionError
from .nodes import AINode

# Re-register environments generated by earlier sessions, so that an SDFG expanded previously
# still resolves the libraries its tasklets were linked against.
from .environments import load_generated_environments

load_generated_environments()

register_library(__name__, "AI")
Loading
Loading