database#
Database initialization, utility functions and table definitions.
Module Attributes
|
Statuses meaning the job is over. |
|
Statuses meaning the job is running right now. |
Functions
|
Adds the item to the database, ignoring any errors to not stop the program flow. |
|
Create and add a new Job to the database. |
|
Add a single log entry for a job. |
|
Add multiple log entries in a single transaction for better performance. |
|
Look up a cached reference benchmark result for the given task content hash and gpu_arch. |
|
Initialize database connections (PostgreSQL or SQLite based on DB_IP env var). |
|
Store a freshly-computed reference benchmark result for later reuse. |
|
Update the progress of a job in the database. |
|
Update the status config, and timestamps of a job in the database. |
|
Persist aggregated token usage for a job. |
- kernelfoundry.eval_pipeline.database.init(cfg)[source]#
Initialize database connections (PostgreSQL or SQLite based on DB_IP env var).
- kernelfoundry.eval_pipeline.database.add_ignore_errors(item)[source]#
Adds the item to the database, ignoring any errors to not stop the program flow.
- kernelfoundry.eval_pipeline.database.add_job(task_origin: str, status: str = 'INIT') int | None[source]#
Create and add a new Job to the database.
- kernelfoundry.eval_pipeline.database.update_job_status(job_id: int, status: str | None = None, started_at: datetime | None = None, finished_at: datetime | None = None, task_id: str | None = None, config: dict | None = None, progress: float | None = None) bool[source]#
Update the status config, and timestamps of a job in the database.
- Parameters:
job_id (int) – The ID of the job to update
status (str) – New status (INIT, RUN, COMPLETE, FAIL)
started_at (datetime, optional) – Timestamp when job started
finished_at (datetime, optional) – Timestamp when job finished
task_id (str, optional) – The task ID to associate with this job
config (dict, optional) – Updated configuration to store in the database
progress (float, optional) – Updated progress value between 0.0 and 1.0
- Returns:
True if update was successful, False otherwise
- Return type:
- kernelfoundry.eval_pipeline.database.update_job_progress(job_id: int, progress: float) bool[source]#
Update the progress of a job in the database.
- kernelfoundry.eval_pipeline.database.update_job_token_usage(job_id: int, input_tokens: int, output_tokens: int, cached_input_tokens: int = 0) bool[source]#
Persist aggregated token usage for a job.
- Parameters:
job_id (int) – The ID of the job to update.
input_tokens (int) – Aggregated prompt/input tokens (excludes cache-read tokens).
output_tokens (int) – Aggregated completion/output tokens.
cached_input_tokens (int) – Aggregated cache-read input tokens. Defaults to 0 for providers with no caching concept.
- Returns:
True if update was successful, False otherwise.
- Return type:
- kernelfoundry.eval_pipeline.database.add_job_log(job_id: int, level: str, message: str, timestamp: datetime | None = None, hostname: str | None = None, kernel_uuid: str | None = None, agent_session_id: str | None = None) int | None[source]#
Add a single log entry for a job.
- Parameters:
job_id (int) – The ID of the job this log belongs to
level (str) – Log level (INFO, DEBUG, WARNING, ERROR)
message (str) – The log message
timestamp (datetime, optional) – Custom timestamp (defaults to server time)
hostname (str | None, optional) – Hostname of the process that emitted the log entry
kernel_uuid (str | None, optional) – UUID of the kernel associated with the log entry
agent_session_id (str | None, optional) – Agent session identifier associated with the log entry
- Returns:
The log entry ID if successful, None otherwise
- Return type:
int | None
- kernelfoundry.eval_pipeline.database.add_job_log_batch(logs: list[dict]) bool[source]#
Add multiple log entries in a single transaction for better performance.
- Parameters:
logs (list[dict]) – List of log dictionaries, each containing: - job_id (int): The ID of the job - hostname (str | None, optional): Hostname of the process that emitted the log entry - kernel_uuid (str | None, optional): UUID of the kernel associated with the log entry - agent_session_id (str | None, optional): Agent session identifier associated with the log entry - level (str): Log level (INFO, DEBUG, WARNING, ERROR) - message (str): The log message - timestamp (datetime, optional): Custom timestamp
- Returns:
True if all logs were added successfully, False otherwise
- Return type:
Example:
logs = [ {"job_id": 1, "level": "INFO", "message": "Starting task"}, {"job_id": 1, "level": "DEBUG", "message": "Processing step 1"}, {"job_id": 1, "level": "ERROR", "message": "Failed at step 2"}, ] add_job_log_batch(logs)
- kernelfoundry.eval_pipeline.database.get_reference_performance(task_hash: str, gpu_arch: str) ReferencePerformance | None[source]#
Look up a cached reference benchmark result for the given task content hash and gpu_arch.
- Parameters:
- Returns:
The cached row if found, None otherwise (including on error).
- Return type:
ReferencePerformance | None
- kernelfoundry.eval_pipeline.database.save_reference_performance(task_name: str | None, task_hash: str, gpu_arch: str, build_result_reference: dict | None, test_result_reference: dict | None, runtime_stats: dict | None = None, job_id: int | None = None) bool[source]#
Store a freshly-computed reference benchmark result for later reuse.
A unique constraint on (task_hash, gpu_arch) means a concurrent duplicate insert is ignored rather than erroring, same as add_ignore_errors is used elsewhere.
- Parameters:
task_name (str | None) – Human-readable task name, for display/debugging only.
task_hash (str) – SHA256 hash of the task’s reference-relevant files.
gpu_arch (str) – GPU architecture the reference was benchmarked on.
build_result_reference (dict | None) – Encoded BuildResult for the reference.
test_result_reference (dict | None) – Encoded TestResult for the reference.
runtime_stats (dict | None) – Human-readable summary of per-benchmark runtime stats.
job_id (int | None) – Job that produced this cache entry.
- Returns:
True if the row was inserted, False otherwise (including if one already existed).
- Return type:
- class kernelfoundry.eval_pipeline.database.Kernel(**kwargs)[source]#
-
- __init__(**kwargs)#
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- class kernelfoundry.eval_pipeline.database.Task(**kwargs)[source]#
-
- __init__(**kwargs)#
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- class kernelfoundry.eval_pipeline.database.Rag(**kwargs)[source]#
-
- __init__(**kwargs)#
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- class kernelfoundry.eval_pipeline.database.Job(**kwargs)[source]#
-
- __init__(**kwargs)#
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- class kernelfoundry.eval_pipeline.database.JobLog(**kwargs)[source]#
-
- __init__(**kwargs)#
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- class kernelfoundry.eval_pipeline.database.ReferencePerformance(**kwargs)[source]#
Cached reference benchmark result, keyed by a content hash of the task’s reference-relevant files (everything except config.yaml/.yml and any file containing an EVOLVE block) plus the gpu_arch it was benchmarked on. Lets repeated build_and_test/submit_task calls reuse a reference result instead of rebuilding and rebenchmarking it every time.
A job’s gpu_arch may list multiple architectures (e.g. “lnl,ptl”); each individual architecture is stored as its own row here rather than the comma-joined string, so a cached single-arch result can be reused by a job that only needs that one arch, and so multi-arch requests are order-independent.
- __init__(**kwargs)#
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
Modules