Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
34 changes: 34 additions & 0 deletions alembic/versions/d3f8b1c5e7a2_add_cpu_core_hour_price.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""add compute_settings.cpu_core_hour_microusd: Krater's price for a CPU core-hour

Revision ID: d3f8b1c5e7a2
Revises: a8d3f1c6e2b9
Create Date: 2026-11-25 22:00:00.000000

An org setting an admin sets on /admin/compute: what one CPU core costs per hour, in micro-dollars. The application
form prices a CPU-only estimate with it (cores x hours x this). The server default 0 means no price is set, and teams
give their own as before.
"""

from collections.abc import Sequence

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "d3f8b1c5e7a2"
down_revision: str | Sequence[str] | None = "a8d3f1c6e2b9"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
"""Upgrade schema."""
op.add_column(
"compute_settings", sa.Column("cpu_core_hour_microusd", sa.Integer(), nullable=False, server_default="0")
)


def downgrade() -> None:
"""Downgrade schema."""
op.drop_column("compute_settings", "cpu_core_hour_microusd")
36 changes: 36 additions & 0 deletions alembic/versions/e6a2c9d4f1b8_value_cpu_only_core_hours.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""value CPU-only core-hours on partner grant days

Revision ID: e6a2c9d4f1b8
Revises: d3f8b1c5e7a2
Create Date: 2026-11-25 23:30:00.000000

Each usage day also keeps the core-hours of jobs that used no GPU, the CPU price per core-hour that values them, and
their value. All three are nullable: a day imported before this has no CPU-only figure yet (`NULL`), and the next import
reads the grant's whole history again to fill it in.
"""

from collections.abc import Sequence

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "e6a2c9d4f1b8"
down_revision: str | Sequence[str] | None = "d3f8b1c5e7a2"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
"""Upgrade schema."""
op.add_column("ospool_usage_days", sa.Column("cpu_core_hours", sa.Numeric(14, 4), nullable=True))
op.add_column("ospool_usage_days", sa.Column("core_rate_microusd", sa.BigInteger(), nullable=True))
op.add_column("ospool_usage_days", sa.Column("core_value_cents", sa.BigInteger(), nullable=True))


def downgrade() -> None:
"""Downgrade schema."""
op.drop_column("ospool_usage_days", "core_value_cents")
op.drop_column("ospool_usage_days", "core_rate_microusd")
op.drop_column("ospool_usage_days", "cpu_core_hours")
14 changes: 10 additions & 4 deletions docs/SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Rules (`krater.services.funder_packet`; how-to in [guides/share-with-ospool.md](
- **Which fields.** The admin ticks them on the page too (`funder_packet.FIELDS`); the title always goes. Ticked when
the page opens: summary (the one sentence), how the compute is used, where the training data comes from, status
(with the funding hold, if any), the amount requested (the approved revision's, not an amendment in review; for a
project never approved, its newest revision's), the amount granted (the ledger ceiling), the GPU estimate (card,
project never approved, its newest revision's), the amount granted (the ledger ceiling), the compute estimate (card or CPU-only cores,
count, hours, interruptible or on-demand), the team's names and size, and whether every team member is a verified
US resident, and the OSPool usage of a project with an OSPool grant (see "OSPool grants"). Unticked until the
admin ticks them: the write-up, the experience answer, the contest or professor,
Expand Down Expand Up @@ -232,8 +232,11 @@ The proposal form (`projects/_application.html`) asks, in three parts:
Submission Criteria ask applicants to name their data sources), then two estimates priced at Vast's current rates: the **proof
of concept** and the **finished product**. Each is a card and about how many hours (plus rental type and safety
margin), and each can be overridden twice over: the team can give its own price per card-hour (also how a card
Krater has no price for is estimated), and can request a different amount than the estimate. Reviewers see the
estimate, Krater's own price when the team gave theirs, and the amount requested, flagged when they differ a lot.
Krater has no price for is estimated), and can request a different amount than the estimate. Instead of a card, the
team can pick **CPU only** with a number of cores, priced at the admins' **CPU price per core-hour**
(`/admin/compute`); until an admin sets one, the team gives the machine's price per hour (Krater Compute can't
run CPU-only jobs yet either: this only lets a proposal ask for them). Reviewers see the estimate, Krater's own price when the team gave theirs, and the amount requested, flagged
when they differ a lot.

Only the proof of concept is approved at first: its amount is `budget_requested_cents`. The finished product's amount
is information for reviewers and never enters the budget ledger; the team asks for more with an amendment, which
Expand Down Expand Up @@ -549,7 +552,10 @@ values the usage at what renting the GPU would have cost.
- **Value.** Each day is valued at the grant's price, else Krater's own on-demand price for the GPU (its Vast samples,
else the catalog). A day keeps the price it was first valued at; a day without a price gets one when Krater has
one. An admin changes the GPU or price from the project page (`admin_change_ospool_valuation`), for later days only.
OSG doesn't record which GPU a job used, so the value is an estimate, shown as one.
OSG doesn't record which GPU a job used, so the value is an estimate, shown as one. Core-hours of jobs that used no
GPU (the summary records with no GPU-hours) are valued the same way at Krater's CPU price per core-hour
(`/admin/compute`), each day keeping its first CPU price too; a GPU job's cores come with its GPU's price, so they
aren't counted twice. Days imported before Krater read the CPU-only part are read again from the start, once.
- **Display.** The project shows *Approved · Partner grant*. Its page has a *Partner grant* card (totals, worth, the
last 30 days with usage, when it was last read), seen by anyone who can see the project.
- **Not named outside admin pages.** What members and reviewers see (the badge, the card, the project's Slack
Expand Down
9 changes: 9 additions & 0 deletions docs/dev/pricing.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ summary says "the team's own hourly price; Krater's typical is $X/hr". The amoun
differ from the estimate's total; it starts as the total, and the project page flags a large difference
(`budget_estimate_flag_threshold_percent`). Both estimates are always stored when filled in, whatever was requested.

**CPU only.** The card `<select>` also offers "CPU only" (`*_gpu = cpu`, `estimator_form.CPU_ONLY`) with a core count
(`*_cpu_cores`, 1 to 512). It's priced at cores × the admins' **CPU price per core-hour**
(`compute_settings.cpu_core_hour_microusd`, an organization limit on `/admin/compute`, micro-dollars, 0 = not set),
for either rental type: `rate_source: krater_cpu_price`. With no price set, `*_rate` is required. `*_rate` is always
the whole machine's price per hour, not per core; with a price set, Krater's machine price is kept as
`market_rate_cents`. The stored estimate has `accelerator_name: "CPU only"`, `accelerator_count: 1` and `cpu_cores`;
its summary reads "CPU only, 16 cores × 40h at $0.096/hr ... (Krater's CPU price, $0.006 per core-hour)". Only GPU
estimates leave `cpu_cores` out. Krater Compute itself still rents GPU machines only.

## Estimator: Krater's own Vast samples first

Whenever the worker has a Vast key, compute on or off, it samples Vast every hour (`krater.services.price_history`). The
Expand Down
5 changes: 4 additions & 1 deletion docs/guides/ospool-grants.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ Members and reviewers never see OSPool or OSG named: the badge, the project's ca
## Read the usage

The project page's **OSPool grant** card shows GPU-hours, core-hours, jobs and what that would have cost to rent,
plus the last 30 days with usage. `/admin` lists every grant. Krater reads OSG's accounting once a day; it runs about
plus the last 30 days with usage. GPU-hours are valued at the grant's GPU price. Core-hours of jobs that used no GPU
are valued at Krater's **CPU price per core-hour**, which you set under Organization limits on `/admin/compute`; until
it's set, days with CPU-only work show as not priced yet and get the price once it is. A GPU job's cores come with its
GPU, so they aren't counted twice. `/admin` lists every grant. Krater reads OSG's accounting once a day; it runs about
a day behind, and OSG corrects recent days, so the last few days may still change.

To send the usage to OSPool or another funder, tick **OSPool usage** in the funder packet (`/admin/funders/ospool`).
Expand Down
1 change: 1 addition & 0 deletions docs/guides/reviewing-and-admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ Below the defaults are the **organization limits**, one value for all of Krater:
| Low credit alert | Off | The alerts channel hears when the Vast account's credit falls under this |
| Credit reserve | Off | Krater rents nothing new while the credit wouldn't cover this many hours of every machine it holds plus the new one; jobs wait, saying why |
| Message the submitter when a job ends | 0 (never) | 1: Krater's Slack app messages whoever queued a job when it fails; 2: whenever one ends. On top of the notice in the project's channel |
| CPU price per core-hour | Not set | What the application form prices a CPU-only estimate at (cores × hours × this), and what partner grants' CPU-only core-hours are worth. Until it's set, teams give their own price and that usage waits for a price |
| Delete finished projects' files after | 30 days | A completed or withdrawn project's checkpoints and outputs are deleted this long after it finishes. The date is fixed then and posted in its channel; 0 keeps them |

The spending caps use Krater's own estimate, which trails Vast's charges by up to an hour, so leave a margin.
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/share-with-ospool.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Patchwork ID, the projects and the fields in it.

For each ticked project, its title and the fields you tick. Ticked when the page opens: the one-sentence summary,
how the team will use the compute, where its training data comes from, its status (with *awaiting funding* or
*awaiting 3rd party review* when it's held), the amount requested and granted, the GPU estimate from the application,
*awaiting 3rd party review* when it's held), the amount requested and granted, the compute estimate from the application,
the team's names and size, whether every team member is a verified US resident, and, for a project with an OSPool
grant, its OSPool usage to date (see [ospool-grants.md](ospool-grants.md)).

Expand Down
3 changes: 2 additions & 1 deletion docs/guides/using-krater.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ Your name and Patchwork ID come from Weave. Then:
For each, pick a **card** (a GPU model), **how many**, about how many **hours**, the **rental** type
(interruptible is much cheaper and can pause) and a **safety margin**. Krater works out the cost. You can give your
own price per card-hour (for a card Krater has no price for, say) and request a different amount from the
estimate. Reviewers see the estimate, Krater's price when you gave your own, and the amount you asked for, flagged
estimate. If your project needs no GPU, pick **CPU only** instead of a card and say how many cores; Krater prices
it per core-hour (if it has no CPU price yet, give the machine's price per hour). Reviewers see the estimate, Krater's price when you gave your own, and the amount you asked for, flagged
when they differ a lot.

[GPU pricing](/pricing) shows what each card costs now, and [price history](/pricing/history) how it moves.
Expand Down
3 changes: 3 additions & 0 deletions krater/models/compute_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class ComputeSettings(Base):
credit_reserve_hours: Mapped[int] = mapped_column(sa.Integer, nullable=False, server_default="0")
# Message a job's submitter in Slack when it ends: 0 = never (the default), 1 = when it fails, 2 = always.
dm_job_endings: Mapped[int] = mapped_column(sa.Integer, nullable=False, server_default="0")
# Krater's price for one CPU core for an hour, in micro-dollars: what the application form prices a CPU-only
# estimate at (cores x hours x this). 0 = no price set; teams give their own.
cpu_core_hour_microusd: Mapped[int] = mapped_column(sa.Integer, nullable=False, server_default="0")

# The stop switch: set while an admin has stopped all compute (`krater.services.compute_halt`).
paused_at: Mapped[datetime | None] = mapped_column(sa.DateTime(timezone=True), nullable=True)
Expand Down
18 changes: 17 additions & 1 deletion krater/models/ospool_grant.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class OspoolUsageDay(UUIDPrimaryKeyMixin, Base):
"""One UTC day of a grant's usage, as OSG's accounting summed it (user jobs only, not the pilots that ran them).

OSG corrects recent days, so the import replaces a day's hours. Its price per GPU-hour is the one in force when
the day was first imported, and stays: a day's value doesn't move with later prices.
the day was first imported, and stays: a day's value doesn't move with later prices. CPU-only jobs' core-hours are
valued the same way at Krater's CPU price per core-hour (`/admin/compute`).
"""

__tablename__ = "ospool_usage_days"
Expand All @@ -82,8 +83,23 @@ class OspoolUsageDay(UUIDPrimaryKeyMixin, Base):
#: `gpu_hours` at `rate_microusd`, in cents: what renting it would have cost. `None` without a price.
value_cents: Mapped[int | None] = mapped_column(sa.BigInteger, nullable=True)
imported_at: Mapped[datetime] = mapped_column(sa.DateTime(timezone=True), nullable=False)
#: The part of `core_hours` from jobs that used no GPU. `None` on a day imported before Krater read it; the next
#: import reads the grant's whole history again to fill it in.
cpu_core_hours: Mapped[Decimal | None] = mapped_column(sa.Numeric(14, 4), nullable=True)
#: Krater's CPU price per core-hour that values `cpu_core_hours`, in micro-dollars, kept like `rate_microusd`;
#: `None` while no CPU price is set.
core_rate_microusd: Mapped[int | None] = mapped_column(sa.BigInteger, nullable=True)
#: `cpu_core_hours` at `core_rate_microusd`, in cents. `None` without a price.
core_value_cents: Mapped[int | None] = mapped_column(sa.BigInteger, nullable=True)

grant: Mapped[OspoolGrant] = relationship(back_populates="usage_days")

@property
def worth_cents(self) -> int | None:
"""The day's GPU and CPU value together; `None` when neither has a price."""
if self.value_cents is None and self.core_value_cents is None:
return None
return (self.value_cents or 0) + (self.core_value_cents or 0)

def __repr__(self) -> str:
return f"<OspoolUsageDay {self.day} gpu_hours={self.gpu_hours}>"
26 changes: 24 additions & 2 deletions krater/ospool/accounting.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
that ran them, and counting both would count the hours twice.
- **Days** are UTC, by each record's `EndTime`, so a job counts on the day it ended.
- **Fields.** `GPUHours`, `CoreHours` and `Njobs`. GRACC doesn't say which GPU a job used.
- **CPU-only jobs.** The summary groups records by GPU count, so the `CoreHours` of records with no `GPUHours` are
the cores of jobs that used no GPU. Krater values those at its CPU price; a GPU job's cores come with the GPU's price.
(Checked Nov 25, 2026: 5.63M of the OSPool's 5.66M core-hours that day were CPU-only.)
- **Lag.** OSG's accounting is about a day behind, and corrects recent days, so the import reads a window again.
- **Speed.** GRACC is slow (5 to 25 seconds a query, measured Nov 8, 2026), and the summary alias spans 34 shards.
`pre_filter_shard_size=1` lets it skip the shards whose dates can't match (31 of them for a recent fortnight), which
Expand Down Expand Up @@ -41,6 +44,8 @@ class DayUsage:
gpu_hours: Decimal
core_hours: Decimal
jobs: int
#: The part of `core_hours` from jobs that used no GPU.
cpu_core_hours: Decimal = Decimal(0)


def _decimal(value: object) -> Decimal:
Expand Down Expand Up @@ -68,6 +73,10 @@ def usage_query(project_name: str, start: date, end: date) -> dict:
"gpu": {"sum": {"field": "GPUHours"}},
"core": {"sum": {"field": "CoreHours"}},
"jobs": {"sum": {"field": "Njobs"}},
"cpu_only": {
"filter": {"bool": {"must_not": [{"range": {"GPUHours": {"gt": 0}}}]}},
"aggs": {"core": {"sum": {"field": "CoreHours"}}},
},
},
}
},
Expand All @@ -84,6 +93,7 @@ def parse_usage(body: dict) -> list[DayUsage]:
gpu_hours=_decimal(bucket["gpu"]["value"]),
core_hours=_decimal(bucket["core"]["value"]),
jobs=int(bucket["jobs"]["value"] or 0),
cpu_core_hours=_decimal(bucket["cpu_only"]["core"]["value"]),
)
for bucket in buckets
]
Expand Down Expand Up @@ -129,9 +139,21 @@ def __init__(self) -> None:
self.calls: list[tuple[str, date, date]] = []

def set_day(
self, project_name: str, day: date, *, gpu_hours: str = "0", core_hours: str = "0", jobs: int = 0
self,
project_name: str,
day: date,
*,
gpu_hours: str = "0",
core_hours: str = "0",
jobs: int = 0,
cpu_core_hours: str | None = None,
) -> None:
self._days[(project_name, day)] = DayUsage(day, Decimal(gpu_hours), Decimal(core_hours), jobs)
"""`cpu_core_hours` defaults to all the core-hours on a day with no GPU-hours, and none otherwise."""
if cpu_core_hours is None:
cpu_core_hours = core_hours if Decimal(gpu_hours) == 0 else "0"
self._days[(project_name, day)] = DayUsage(
day, Decimal(gpu_hours), Decimal(core_hours), jobs, Decimal(cpu_core_hours)
)

def daily_usage(self, project_name: str, start: date, end: date) -> list[DayUsage]:
self.calls.append((project_name, start, end))
Expand Down
16 changes: 15 additions & 1 deletion krater/services/compute_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class PolicyField:
# "bp": stored in basis points, shown and entered as a fraction (9500 <-> 0.95).
# "usd_per_tb": stored in micro-dollars per GB, shown and entered in dollars per TB (20000 <-> 20).
# "usd": stored in cents, shown and entered in dollars (12550 <-> 125.5).
# "usd_micro": stored in micro-dollars, shown and entered in dollars (6000 <-> 0.006).
kind: str = "int"


Expand Down Expand Up @@ -279,6 +280,18 @@ class PolicyField:
2,
0,
),
PolicyField(
"cpu_core_hour_microusd",
"CPU price per core-hour",
"What the application form prices a CPU-only estimate at: cores × hours × this. Teams can give their own "
"price instead, and reviewers see both. Partner grants' CPU-only core-hours are valued at it too. Up to six "
"decimal places. 0 = no price: teams must give their own.",
"USD",
0,
1_000_000,
0,
kind="usd_micro",
),
)
ORG_FIELDS_BY_NAME = {f.name: f for f in ORG_FIELDS}
AUDIT_ORG = "compute_org_limits_update"
Expand Down Expand Up @@ -321,7 +334,7 @@ def values(self) -> dict[str, int]:


#: What a scaled kind's stored integer is divided by to show it: basis points per 1, micro-dollars per GB per $/TB.
_SCALED = {"bp": 10_000, "usd_per_tb": 1_000, "usd": 100}
_SCALED = {"bp": 10_000, "usd_per_tb": 1_000, "usd": 100, "usd_micro": 1_000_000}


def format_value(field: PolicyField, value: int | None) -> str:
Expand Down Expand Up @@ -488,6 +501,7 @@ class OrgLimits:
finished_files_days: int
credit_reserve_hours: int
dm_job_endings: int
cpu_core_hour_microusd: int

def values(self) -> dict[str, int]:
return {f.name: getattr(self, f.name) for f in ORG_FIELDS}
Expand Down
Loading
Loading