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
3 changes: 3 additions & 0 deletions book/src/lib/autograd.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Public module of the `aprender-core` crate.

## Example

<!-- example-cost: skip -->
```rust
use aprender::autograd::{Tensor, no_grad};
// See `cargo doc -p aprender-core --open` for full API reference.
Expand Down Expand Up @@ -40,6 +41,7 @@ inspecting the graph, and the `GradFn` trait that custom ops implement.

### Pattern 1: A simple gradient computation

<!-- example-cost: skip -->
```rust
use aprender::autograd::Tensor;

Expand All @@ -55,6 +57,7 @@ assert!((g.item() - 6.0).abs() < 1e-5);

### Pattern 2: Inference without graph overhead via `no_grad`

<!-- example-cost: skip -->
```rust
use aprender::autograd::{Tensor, no_grad, is_grad_enabled};

Expand Down
3 changes: 3 additions & 0 deletions book/src/lib/classification.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Public module of the `aprender-core` crate.

## Example

<!-- example-cost: skip -->
```rust
use aprender::classification::LogisticRegression;
// See `cargo doc -p aprender-core --open` for full API reference.
Expand Down Expand Up @@ -38,6 +39,7 @@ the targets are discrete labels.

### Pattern 1: Logistic regression on separable data

<!-- example-cost: skip -->
```rust
use aprender::metrics::classification::accuracy;
use aprender::prelude::*;
Expand All @@ -61,6 +63,7 @@ println!("accuracy: {:.2}", acc);

### Pattern 2: KNN with custom distance metric

<!-- example-cost: skip -->
```rust
use aprender::classification::{DistanceMetric, KNearestNeighbors};
use aprender::primitives::Matrix;
Expand Down
3 changes: 3 additions & 0 deletions book/src/lib/format.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Public module of the `aprender-core` crate.

## Example

<!-- example-cost: skip -->
```rust
use aprender::format::{ModelCard, AprConverter, ConvertOptions};
// See `cargo doc -p aprender-core --open` for full API reference.
Expand Down Expand Up @@ -42,6 +43,7 @@ The submodules `quantize`, `gguf`, `onnx`, `sharded`, `signing`, and

### Pattern 1: Attach a model card to a checkpoint

<!-- example-cost: skip -->
```rust
use aprender::format::{ModelCard, TrainingDataInfo};

Expand All @@ -62,6 +64,7 @@ println!("model card: {}", card.name);

### Pattern 2: Diff two checkpoints tensor-by-tensor

<!-- example-cost: skip -->
```rust
use aprender::format::{DiffOptions, DiffCategory};
// AprConverter / diff_models work on real on-disk artefacts;
Expand Down
2 changes: 2 additions & 0 deletions book/src/lib/interpret.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ make this prediction?"

### Pattern 1: Closed-form attribution for a linear model

<!-- example-cost: skip -->
```rust
use aprender::interpret::FeatureContributions;
use aprender::primitives::Vector;
Expand All @@ -61,6 +62,7 @@ assert!(contributions.verify_sum(1e-5));

### Pattern 2: Permutation importance

<!-- example-cost: skip -->
```rust
use aprender::interpret::PermutationImportance;
use aprender::primitives::Vector;
Expand Down
3 changes: 3 additions & 0 deletions book/src/lib/loss.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Public module of the `aprender-core` crate.

## Example

<!-- example-cost: skip -->
```rust
use aprender::loss::{MSELoss, MAELoss, HuberLoss, Loss};
// See `cargo doc -p aprender-core --open` for full API reference.
Expand Down Expand Up @@ -37,6 +38,7 @@ passed around generically by optimizers and training loops.

### Pattern 1: Compute MSE and MAE on a single prediction vector

<!-- example-cost: skip -->
```rust
use aprender::loss::{mse_loss, mae_loss, huber_loss};
use aprender::primitives::Vector;
Expand All @@ -54,6 +56,7 @@ assert!(mse > 0.0 && mae > 0.0);

### Pattern 2: Pass losses to generic code via the `Loss` trait

<!-- example-cost: skip -->
```rust
use aprender::loss::{Loss, MSELoss, HuberLoss};
use aprender::primitives::Vector;
Expand Down
3 changes: 3 additions & 0 deletions book/src/lib/model_selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Public module of the `aprender-core` crate.

## Example

<!-- example-cost: skip -->
```rust
use aprender::model_selection::{train_test_split, cross_validate, KFold, StratifiedKFold};
// See `cargo doc -p aprender-core --open` for full API reference.
Expand Down Expand Up @@ -41,6 +42,7 @@ confidence intervals around your point estimates.

### Pattern 1: 5-fold cross-validation of a linear model

<!-- example-cost: skip -->
```rust
use aprender::model_selection::{cross_validate, KFold};
use aprender::prelude::*;
Expand All @@ -58,6 +60,7 @@ println!("cv R²: mean={:.4} std={:.4}", result.mean(), result.std());

### Pattern 2: Stratified split for classification

<!-- example-cost: skip -->
```rust
use aprender::model_selection::StratifiedKFold;
use aprender::primitives::Vector;
Expand Down
3 changes: 3 additions & 0 deletions book/src/lib/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Public module of the `aprender-core` crate.

## Example

<!-- example-cost: skip -->
```rust
use aprender::models::Qwen2Model;
// See `cargo doc -p aprender-core --open` for full API reference.
Expand Down Expand Up @@ -42,6 +43,7 @@ accessible so you can compose custom variants.

### Pattern 1: Construct a BERT encoder from a config

<!-- example-cost: skip -->
```rust
use aprender::models::{BertConfig, BertEncoder};

Expand All @@ -60,6 +62,7 @@ println!("encoder ready with {} layers", config.num_hidden_layers);

### Pattern 2: Inspect Qwen2 components

<!-- example-cost: skip -->
```rust
use aprender::models::qwen2::{Qwen2MLP, Embedding};

Expand Down
3 changes: 3 additions & 0 deletions book/src/lib/nn.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Public module of the `aprender-core` crate.

## Example

<!-- example-cost: skip -->
```rust
use aprender::nn::{Sequential, Linear, ReLU};
// See `cargo doc -p aprender-core --open` for full API reference.
Expand Down Expand Up @@ -44,6 +45,7 @@ The submodule `nn::transformer` exposes attention + transformer-block types;

### Pattern 1: An MLP via `Sequential`

<!-- example-cost: skip -->
```rust
use aprender::nn::{Sequential, Linear, ReLU};

Expand All @@ -58,6 +60,7 @@ println!("layers: {}", model.len());

### Pattern 2: Use RMSNorm (transformer-style)

<!-- example-cost: skip -->
```rust
use aprender::nn::{Linear, RMSNorm};
use aprender::nn::module::Module;
Expand Down
2 changes: 2 additions & 0 deletions book/src/lib/online.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ reinforcement learning from verifier (`rlvr`), and tokenizer surgery.

### Pattern 1: Streaming linear regression

<!-- example-cost: skip -->
```rust
use aprender::online::OnlineLinearRegression;

Expand All @@ -66,6 +67,7 @@ for (x, _y) in &samples {

### Pattern 2: Logistic regression with configurable decay

<!-- example-cost: skip -->
```rust
use aprender::online::{OnlineLogisticRegression, OnlineLearnerConfig, LearningRateDecay};

Expand Down
3 changes: 3 additions & 0 deletions book/src/lib/text.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Public module of the `aprender-core` crate.

## Example

<!-- example-cost: skip -->
```rust
use aprender::text::{Tokenizer, ChatTemplateEngine, ChatMessage};
// See `cargo doc -p aprender-core --open` for full API reference.
Expand Down Expand Up @@ -40,6 +41,7 @@ templates a conversation runs through here.

### Pattern 1: Detect a chat template by model name

<!-- example-cost: skip -->
```rust
use aprender::text::{detect_format_from_name, TemplateFormat};

Expand All @@ -52,6 +54,7 @@ assert!(matches!(other, Some(TemplateFormat::Llama2)));

### Pattern 2: Render a multi-turn conversation

<!-- example-cost: skip -->
```rust
use aprender::text::{ChatMessage, ChatMLTemplate, ChatTemplateEngine};

Expand Down
11 changes: 9 additions & 2 deletions scripts/_build_rust_compile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def extract() -> list[dict]:
if not line.strip():
continue
r = json.loads(line)
if r["lang"] == "rust" and r["path"].startswith("book/src/lib/"):
# Exclude rust blocks marked cost=skip (pending API alignment, etc.)
if r["lang"] == "rust" and r["path"].startswith("book/src/lib/") \
and r.get("cost") != "skip":
records.append(r)
return records

Expand Down Expand Up @@ -59,9 +61,14 @@ def main() -> int:
"\n"
"#![allow(dead_code, unused_imports, unused_variables)]\n"
)
seen: dict[str, int] = {}
for r in records:
stem = Path(r["path"]).stem # e.g. "active_learning"
mod_name = "block_" + sanitize_mod(stem)
base = "block_" + sanitize_mod(stem)
# Disambiguate: each rust block in the same chapter gets a unique mod name
n = seen.get(base, 0)
seen[base] = n + 1
mod_name = base if n == 0 else f"{base}_{n}"
lines.append(f"\n// from {r['path']} (lines {r['line_start']}..{r['line_end']})")
lines.append(f"mod {mod_name} {{")
lines.append(" #[allow(dead_code)]")
Expand Down
2 changes: 1 addition & 1 deletion scripts/extract_book_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
CLOSE_RE = re.compile(r"^```\s*$")
COST_RE = re.compile(r"^<!--\s*example-cost:\s*([^>]+?)\s*-->\s*$")

VALID_COSTS = {"trivial", "model-required", "gpu", "destructive", "interactive"}
VALID_COSTS = {"trivial", "model-required", "gpu", "destructive", "interactive", "skip"}


def parse_cost_annotation(line: str) -> tuple[str, str | None]:
Expand Down
Loading