Fit cache¶
Fits and runs keyed by content hashes, data digests, configuration, seeds, and engine identity.
Model.fit takes a cache through its cache argument.
fits
¶
Content-addressed caching of fits and runs.
A fit is determined by the meaning of the program fitted, the data it is
fitted to, the sites held fixed, the inference and runtime configuration, the
seeds, and the engine that computes it. FitKey
records exactly these, each as a digest:
- the entry hash: the content hash of the checked entry point
(
module_hashes), which is invariant under renaming, reordering, comments, and formatting, together with the digest of the checked interpretation bindings that accompany it; - the entry's observable names: its site labels, the names of the parameters a run supplies by name, and returned names, which key the stored result's values. A rename of anything else (a computation, a family, a handler, a local, a domain parameter, which takes its value by position, the program itself) leaves the key unchanged and reuses the stored fit;
- the data, one digest per program parameter, by parameter position;
- the fixed sites, one digest per conditioned site, by site ordinal;
- the configuration: the inference method and every option of the fit or run;
- the seeds;
- the engine identity: the quivers version, the kernel ABI, the content-hash format, the torch and Python versions, and the platform.
A cache hit returns the stored artifact unchanged: a fit is reloaded with
load_fit from the bytes
save_fit wrote, and a run returns the
JSON payload it printed. Anything without a content identity (a native
family implementation, a programmatic runtime provider, a method configured
without a seed) is refused rather than cached, because no stored artifact
could stand for it.
ExternalValue
¶
ExternalValue = None | bool | int | float | str | Tensor | Model | ArrayLike | Sequence[ExternalValue] | Mapping[str, ExternalValue]
A value supplied to a fit or run from outside the program: a datum, a site value, a static argument, or a configuration record.
FitKind
¶
What a key addresses: a Model.fit
result or an invoke_entry run.
ArrayLike
¶
Bases: Protocol
A value that exposes an array view, such as a NumPy array.
FitCacheError
¶
Bases: ValueError
A fit or run has no content identity, so it cannot be cached.
KeyedDigest
didactic-model
¶
Bases: Model
The digest of one value at one position of a key.
| PARAMETER | DESCRIPTION |
|---|---|
position
|
A parameter position or a site ordinal.
TYPE:
|
digest
|
The value's digest.
TYPE:
|
FitKey
didactic-model
¶
FitKey(*, kind: FitKind, entry: str, companions: str, source: str, names: tuple[str, ...], data: tuple[KeyedDigest, ...], fixed_sites: tuple[KeyedDigest, ...], configuration: str, seeds: tuple[int, ...], engine: str)
Bases: Model
Everything that determines a fit or run, as digests.
| PARAMETER | DESCRIPTION |
|---|---|
kind
|
A fit or a run.
TYPE:
|
entry
|
The content hash of the entry point.
TYPE:
|
companions
|
The digest of the checked interpretation bindings the entry runs with, in the module's content context.
TYPE:
|
source
|
For a fit, the digest of the program source's modules
(
TYPE:
|
names
|
The entry's observable names, in ordinal order.
TYPE:
|
data
|
Each supplied parameter's position with the digest of its value.
TYPE:
|
fixed_sites
|
Each conditioned site's ordinal among
TYPE:
|
configuration
|
The digest of the inference method and the options of the fit or run.
TYPE:
|
seeds
|
The seeds.
TYPE:
|
engine
|
The digest of the engine identity.
TYPE:
|
digest
¶
The store key of the fit or run.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The digest of every component. |
Source code in src/quivers/incremental/fits.py
FitCacheEvent
didactic-model
¶
FitCacheEvent(*, kind: FitKind, key: str, hit: bool)
Bases: Model
One lookup of a cache.
| PARAMETER | DESCRIPTION |
|---|---|
kind
|
A fit or a run.
TYPE:
|
key
|
The key's digest.
TYPE:
|
hit
|
Whether the stored artifact was returned.
TYPE:
|
CachedRun
didactic-model
¶
CachedRun(*, key: str, hit: bool, payload: JsonValue = field(opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: ValueModel
A run's result, as qvr run --json prints it.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The digest of the run's key.
TYPE:
|
hit
|
Whether the payload came from the store.
TYPE:
|
payload
|
The run's mutable JSON data, compared by identity.
TYPE:
|
FitCache
¶
FitCache(store: ArtifactStore, *, engine: str | None = None, factories: Mapping[str, ArtifactFactory] | None = None)
A content-addressed cache of fits and runs in an artifact store.
| PARAMETER | DESCRIPTION |
|---|---|
store
|
Where artifacts persist.
TYPE:
|
engine
|
The engine identity digest;
TYPE:
|
factories
|
Explicit contracts for configuration values the fitted artifact format
does not know, passed to
TYPE:
|
Source code in src/quivers/incremental/fits.py
for_project
classmethod
¶
for_project(start: Path | None = None) -> FitCache
The cache of the project a path belongs to.
| PARAMETER | DESCRIPTION |
|---|---|
start
|
A path inside the project; the working directory when None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FitCache
|
A cache in the project's artifact store. |
| RAISES | DESCRIPTION |
|---|---|
StoreError
|
If no project root is found. |
Source code in src/quivers/incremental/fits.py
fit_key
¶
fit_key(model: Model, data: Mapping[str, ExternalValue], *, method: InferenceMethod[ModelFit], parameters: Mapping[str, ExternalValue] | None = None, input: Tensor | None = None, seed: int = 0, sample_prior: PriorMode = 'no', num_prior_samples: int = 100, prior_seed: int = 1, snapshot_policy: SnapshotPolicy = 'clone') -> FitKey
The key of a Model.fit call.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
The checked model.
TYPE:
|
data
|
The external data.
TYPE:
|
method
|
The inference method.
TYPE:
|
parameters
|
Static specialization arguments.
TYPE:
|
input
|
The domain input.
TYPE:
|
seed
|
The compilation seed.
TYPE:
|
sample_prior
|
The prior-sampling mode.
TYPE:
|
num_prior_samples
|
The prior draw budget.
TYPE:
|
prior_seed
|
The prior stream's seed.
TYPE:
|
snapshot_policy
|
The refit-data ownership.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FitKey
|
The key. |
| RAISES | DESCRIPTION |
|---|---|
FitCacheError
|
If the model uses a custom family catalog, a datum or the method has no portable contract, the method declares no seed, or a datum names no parameter of the entry. |
ValueError
|
If labeled data does not match the axes of its parameter's type. |
Source code in src/quivers/incremental/fits.py
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 | |
fit
¶
fit(model: Model, data: Mapping[str, ExternalValue], *, method: InferenceMethod[ModelFit], parameters: Mapping[str, ExternalValue] | None = None, input: Tensor | None = None, seed: int = 0, sample_prior: PriorMode = 'no', num_prior_samples: int = 100, prior_seed: int = 1, snapshot_policy: SnapshotPolicy = 'clone') -> ModelFit
Fit a model, reusing a stored fit with the same key.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
The checked model.
TYPE:
|
data
|
The external data.
TYPE:
|
method
|
The inference method.
TYPE:
|
parameters
|
Static specialization arguments.
TYPE:
|
input
|
The domain input.
TYPE:
|
seed
|
The compilation seed.
TYPE:
|
sample_prior
|
The prior-sampling mode.
TYPE:
|
num_prior_samples
|
The prior draw budget.
TYPE:
|
prior_seed
|
The prior stream's seed.
TYPE:
|
snapshot_policy
|
The refit-data ownership.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ModelFit
|
On a hit, the stored fit reloaded exactly as |
| RAISES | DESCRIPTION |
|---|---|
FitCacheError
|
If the fit has no content identity, or the method does not return
a |
StoreError
|
If the stored artifact is corrupt. |
Source code in src/quivers/incremental/fits.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 | |
run_key
¶
run_key(module: QiecModule, name: str, arguments: Sequence[HostValue] = (), *, data: Mapping[str, HostValue] | None = None, sites: Mapping[str, HostValue] | None = None, static_arguments: Sequence[str] = (), runtime: RuntimeConfiguration | None = None, fuel: int | None = None, seed: int | None = None, numbers: NumberDomain | None = None) -> FitKey
The key of an invoke_entry run.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked module.
TYPE:
|
name
|
The entry's name: a program or a computation.
TYPE:
|
arguments
|
Positional value arguments.
TYPE:
|
data
|
A program's parameters by name.
TYPE:
|
sites
|
Conditioned sites by label.
TYPE:
|
static_arguments
|
TYPE:
|
runtime
|
The runtime providers.
TYPE:
|
fuel
|
The step budget.
TYPE:
|
seed
|
The reference generator's seed.
TYPE:
|
numbers
|
The number domain the reference machine computes in; the default floating domain when None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FitKey
|
The key. |
| RAISES | DESCRIPTION |
|---|---|
FitCacheError
|
If the run has no seed, uses programmatic providers, names a datum or site the entry does not have, or passes a value with no portable contract. |
KeyError
|
If the module has no entry or computation of that name. |
ExecutionFailure
|
With code |
Source code in src/quivers/incremental/fits.py
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 | |
run
¶
run(module: QiecModule, name: str, arguments: Sequence[HostValue] = (), *, data: Mapping[str, HostValue] | None = None, sites: Mapping[str, HostValue] | None = None, static_arguments: Sequence[str] = (), runtime: RuntimeConfiguration | None = None, fuel: int | None = None, seed: int | None = None, numbers: NumberDomain | None = None) -> CachedRun
Invoke an entry, reusing a stored run with the same key.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked module.
TYPE:
|
name
|
The entry's name.
TYPE:
|
arguments
|
Positional value arguments.
TYPE:
|
data
|
A program's parameters by name.
TYPE:
|
sites
|
Conditioned sites by label.
TYPE:
|
static_arguments
|
TYPE:
|
runtime
|
The runtime providers.
TYPE:
|
fuel
|
The step budget.
TYPE:
|
seed
|
The reference generator's seed; required.
TYPE:
|
numbers
|
The number domain the reference machine computes in; the default floating domain when None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CachedRun
|
The run's JSON payload, from the store on a hit. |
| RAISES | DESCRIPTION |
|---|---|
FitCacheError
|
If the run has no content identity. |
ExecutionFailure
|
If the run fails. |
StoreError
|
If the stored payload is corrupt. |
Source code in src/quivers/incremental/fits.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 | |
program_source_digest
¶
program_source_digest(source: ProgramSource) -> str
The digest that identifies a model's program source.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The root module and the modules it imports.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The digest of each module's path with the alpha-normalized statement
digest of its text ( |
Source code in src/quivers/incremental/fits.py
value_digest
¶
value_digest(value: ExternalValue | InferenceMethod[ModelFit], factories: Mapping[str, ArtifactFactory] | None = None) -> str
The digest of one external value.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
A datum, a site value, a configuration record, or an inference method: anything the fitted artifact format has a portable contract for.
TYPE:
|
factories
|
Explicit contracts for values the format does not know.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The digest of the value's portable encoding. |
| RAISES | DESCRIPTION |
|---|---|
FitCacheError
|
If the value has no portable contract, so no stored fit could have been computed from it. |