Skip to content

Make rust-ml repository publish-ready and pedagogy-focused - #8

Merged
hghalebi merged 25 commits into
mainfrom
codex/add-ci-and-gemini-writing-review
May 28, 2026
Merged

Make rust-ml repository publish-ready and pedagogy-focused#8
hghalebi merged 25 commits into
mainfrom
codex/add-ci-and-gemini-writing-review

Conversation

@hghalebi

Copy link
Copy Markdown
Owner

Summary

  • Expand and unify lesson/curriculum surface for CS336-based ML content in a publish-ready structure.
  • Integrate inference lesson and bridge module consistency with existing teaching architecture.
  • Add and align publish-readiness checks and public-content validation gates.
  • Keep implementations typed-first, newtype-heavy, and aligned with the existing public Rust contract.

Validation

  • python3 scripts/check_course_content.py
  • python3 scripts/check_public_content.py
  • python3 scripts/check_rust_teaching_contract.py
  • python3 scripts/check_lesson_rust_snippets.py
  • python3 scripts/check_teaching_examples.py
  • cargo fmt --manifest-path code/Cargo.toml --all --check
  • cargo clippy --manifest-path code/Cargo.toml --workspace --all-targets --all-features
  • cargo test --manifest-path code/Cargo.toml --workspace --all-targets

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown

Important

Review skipped

Too many files!

This PR contains 234 files, which is 84 over the limit of 150.

To get a review, narrow the scope:
• coderabbit review --type committed # exclude uncommitted changes
• coderabbit review --dir # limit to a subdirectory
• coderabbit review --base # compare against a closer base

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 22ee8446-9bde-4cb4-b8b8-410b6fb1f8a9

📥 Commits

Reviewing files that changed from the base of the PR and between 076b265 and d8c47d4.

📒 Files selected for processing (234)
  • .ai/mcp/mcp.json
  • .github/workflows/ci.yml
  • .gitignore
  • .idea/.name
  • .idea/inspectionProfiles/Project_Default.xml
  • .idea/jsLinters/eslint.xml
  • .idea/jsonCatalog.xml
  • .idea/misc.xml
  • .idea/opentofu_settings.xml
  • .idea/prettier.xml
  • .idea/terraform.xml
  • .idea/terragrunt.xml
  • CS336-RUST-EQUIVALENT.md
  • LEARNING-PATH.md
  • PUBLIC_CONTENT.md
  • README.md
  • assignments/cs336-rust/01-basics.md
  • assignments/cs336-rust/02-systems.md
  • assignments/cs336-rust/03-scaling.md
  • assignments/cs336-rust/04-data.md
  • assignments/cs336-rust/05-alignment.md
  • assignments/cs336-rust/README.md
  • book/README.md
  • code/Cargo.toml
  • code/README.md
  • code/alignment/Cargo.toml
  • code/alignment/README.md
  • code/alignment/examples/01_instruction_example.rs
  • code/alignment/examples/02_preference_signal.rs
  • code/alignment/examples/03_verifier_feedback.rs
  • code/alignment/examples/04_audit_record.rs
  • code/alignment/examples/05_alignment_workflow.rs
  • code/alignment/examples/06_public_release.rs
  • code/alignment/src/error.rs
  • code/alignment/src/lib.rs
  • code/attention/Cargo.toml
  • code/attention/README.md
  • code/attention/examples/01_score_one_pair.rs
  • code/attention/examples/02_softmax_focus.rs
  • code/attention/examples/03_weighted_sum.rs
  • code/attention/examples/04_attention_trace.rs
  • code/attention/examples/05_public_trace.rs
  • code/attention/src/error.rs
  • code/attention/src/lib.rs
  • code/category_lens/Cargo.toml
  • code/category_lens/README.md
  • code/category_lens/examples/01_objects_and_maps.rs
  • code/category_lens/examples/02_compose_neuron_forward.rs
  • code/category_lens/examples/03_composition_failure.rs
  • code/category_lens/examples/04_public_composition_trace.rs
  • code/category_lens/src/error.rs
  • code/category_lens/src/lib.rs
  • code/data/Cargo.toml
  • code/data/README.md
  • code/data/examples/01_normalize_documents.rs
  • code/data/examples/02_filter_and_dedup.rs
  • code/data/examples/03_build_shard.rs
  • code/data/examples/04_source_mixture.rs
  • code/data/examples/05_public_manifest.rs
  • code/data/src/error.rs
  • code/data/src/lib.rs
  • code/evaluation/Cargo.toml
  • code/evaluation/README.md
  • code/evaluation/examples/01_score_prediction.rs
  • code/evaluation/examples/02_accuracy_report.rs
  • code/evaluation/examples/03_reject_mismatched_ids.rs
  • code/evaluation/examples/04_compare_runs.rs
  • code/evaluation/examples/05_public_report.rs
  • code/evaluation/src/error.rs
  • code/evaluation/src/lib.rs
  • code/inference/Cargo.toml
  • code/inference/README.md
  • code/inference/examples/01_greedy_decode.rs
  • code/inference/examples/02_sampling_controls.rs
  • code/inference/examples/03_kv_cache_trace.rs
  • code/inference/examples/04_latency_budget.rs
  • code/inference/examples/05_public_trace.rs
  • code/inference/src/error.rs
  • code/inference/src/lib.rs
  • code/kernels/Cargo.toml
  • code/kernels/README.md
  • code/kernels/examples/01_elementwise_gelu.rs
  • code/kernels/examples/02_row_sum_reduction.rs
  • code/kernels/examples/03_tiled_matvec.rs
  • code/kernels/examples/04_kernel_estimate.rs
  • code/kernels/examples/05_public_report.rs
  • code/kernels/src/error.rs
  • code/kernels/src/lib.rs
  • code/lm_basics/Cargo.toml
  • code/lm_basics/README.md
  • code/lm_basics/examples/01_tokenize_and_encode.rs
  • code/lm_basics/examples/02_next_token_batch.rs
  • code/lm_basics/examples/03_uniform_loss.rs
  • code/lm_basics/examples/04_training_step.rs
  • code/lm_basics/examples/05_public_training_example.rs
  • code/lm_basics/src/error.rs
  • code/lm_basics/src/lib.rs
  • code/mlp/Cargo.toml
  • code/mlp/README.md
  • code/mlp/examples/01_hidden_features.rs
  • code/mlp/examples/02_shape_flow.rs
  • code/mlp/examples/03_forward_trace.rs
  • code/mlp/examples/04_xor_table.rs
  • code/mlp/examples/05_public_trace.rs
  • code/mlp/src/error.rs
  • code/mlp/src/lib.rs
  • code/neuron/README.md
  • code/neuron/examples/01_weighted_sum.rs
  • code/neuron/examples/02_forward_pass.rs
  • code/neuron/examples/03_one_step_training.rs
  • code/neuron/examples/04_and_gate_epoch.rs
  • code/neuron/examples/05_public_training_step.rs
  • code/neuron/examples/token_targets.rs
  • code/neuron/examples/train_bigram_cycle.rs
  • code/neuron/examples/train_or_gate.rs
  • code/neuron/src/error.rs
  • code/neuron/src/lib.rs
  • code/parallelism/Cargo.toml
  • code/parallelism/README.md
  • code/parallelism/examples/01_data_parallel_batch.rs
  • code/parallelism/examples/02_tensor_parallel_width.rs
  • code/parallelism/examples/03_collective_all_reduce.rs
  • code/parallelism/examples/04_pipeline_schedule.rs
  • code/parallelism/examples/05_public_report.rs
  • code/parallelism/src/error.rs
  • code/parallelism/src/lib.rs
  • code/scaling/Cargo.toml
  • code/scaling/README.md
  • code/scaling/examples/01_record_runs.rs
  • code/scaling/examples/02_fit_power_law.rs
  • code/scaling/examples/03_forecast_loss.rs
  • code/scaling/examples/04_report_limitations.rs
  • code/scaling/examples/05_tradeoff_decision.rs
  • code/scaling/examples/06_public_report.rs
  • code/scaling/src/error.rs
  • code/scaling/src/lib.rs
  • code/systems/Cargo.toml
  • code/systems/README.md
  • code/systems/examples/01_memory_accounting.rs
  • code/systems/examples/02_attention_flops.rs
  • code/systems/examples/03_median_timing.rs
  • code/systems/examples/04_arithmetic_intensity.rs
  • code/systems/examples/05_memory_hierarchy.rs
  • code/systems/examples/06_public_report.rs
  • code/systems/src/error.rs
  • code/systems/src/lib.rs
  • code/transformer/README.md
  • code/transformer/examples/architecture_config.rs
  • code/transformer/examples/encoder_demo.rs
  • code/transformer/examples/expert_routing.rs
  • code/transformer/examples/public_encoder_trace.rs
  • code/transformer/src/architecture.rs
  • code/transformer/src/attention.rs
  • code/transformer/src/error.rs
  • code/transformer/src/experts.rs
  • code/transformer/src/lib.rs
  • code/transformer/src/math.rs
  • code/transformer/src/transformer.rs
  • code/transformer/src/types.rs
  • lessons/00-learning-lens.md
  • lessons/01-foundations/01-core-idea.md
  • lessons/01-foundations/02-reading-algebra-like-a-programmer.md
  • lessons/01-foundations/03-rust-syntax-for-ml.md
  • lessons/01-foundations/README.md
  • lessons/01-foundations/exercises.md
  • lessons/01-foundations/solutions.md
  • lessons/02-vectors/01-scalars-vectors-matrices.md
  • lessons/02-vectors/02-sum-dot-product-and-mat-vec.md
  • lessons/02-vectors/03-sigmoid-loss-and-gradient-descent.md
  • lessons/02-vectors/README.md
  • lessons/02-vectors/exercises.md
  • lessons/02-vectors/solutions.md
  • lessons/03-neuron/01-rust-essentials-for-a-tiny-neuron.md
  • lessons/03-neuron/02-neuron-as-a-chain-of-functions.md
  • lessons/03-neuron/README.md
  • lessons/03-neuron/exercises.md
  • lessons/03-neuron/solutions.md
  • lessons/04-learning/01-training-step-as-feedback.md
  • lessons/04-learning/02-epochs-and-loss-traces.md
  • lessons/04-learning/README.md
  • lessons/04-learning/exercises.md
  • lessons/04-learning/solutions.md
  • lessons/05-mlp/01-hidden-layers-as-representations.md
  • lessons/05-mlp/02-shape-flow-through-an-mlp.md
  • lessons/05-mlp/README.md
  • lessons/05-mlp/exercises.md
  • lessons/05-mlp/solutions.md
  • lessons/06-attention/01-tokens-as-vectors-in-a-sequence.md
  • lessons/06-attention/02-query-key-value-roles.md
  • lessons/06-attention/03-scores-weights-and-value-mixing.md
  • lessons/06-attention/README.md
  • lessons/06-attention/exercises.md
  • lessons/06-attention/solutions.md
  • lessons/07-transformer/01-tiny-transformer-from-first-principles.md
  • lessons/07-transformer/02-typed-rust-transformer-with-linear-attention.md
  • lessons/07-transformer/03-transformer-encoder-in-small-chunks.md
  • lessons/07-transformer/README.md
  • lessons/07-transformer/exercises.md
  • lessons/07-transformer/solutions.md
  • lessons/08-language-modeling/01-text-to-token-ids.md
  • lessons/08-language-modeling/02-next-token-batches-loss-and-update.md
  • lessons/08-language-modeling/03-public-text-boundary.md
  • lessons/08-language-modeling/README.md
  • lessons/08-language-modeling/exercises.md
  • lessons/08-language-modeling/solutions.md
  • lessons/09-systems/01-shapes-elements-bytes-and-flops.md
  • lessons/09-systems/02-timing-intensity-and-memory-hierarchy.md
  • lessons/09-systems/03-public-systems-report-boundary.md
  • lessons/09-systems/README.md
  • lessons/09-systems/exercises.md
  • lessons/09-systems/solutions.md
  • lessons/10-kernels/01-elementwise-maps-and-reductions.md
  • lessons/10-kernels/02-tiling-a-matrix-vector-kernel.md
  • lessons/10-kernels/03-public-kernel-report-boundary.md
  • lessons/10-kernels/README.md
  • lessons/10-kernels/exercises.md
  • lessons/10-kernels/solutions.md
  • lessons/11-inference/01-autoregressive-decoding-state-trace.md
  • lessons/11-inference/02-public-decode-boundary-and-latency.md
  • lessons/11-inference/README.md
  • lessons/11-inference/exercises.md
  • lessons/11-inference/solutions.md
  • lessons/CONCEPT-ATLAS.md
  • lessons/COURSE-STRUCTURE.md
  • lessons/README.md
  • references/README.md
  • references/courses/cs336-language-modeling-from-scratch.md
  • references/transcripts/attention-is-all-you-need-transformer-model-explanation-inference-training.md
  • scripts/check_course_content.py
  • scripts/check_lesson_rust_snippets.py
  • scripts/check_public_content.py
  • scripts/check_rust_teaching_contract.py
  • scripts/check_teaching_crates.py
  • scripts/check_teaching_examples.py

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/add-ci-and-gemini-writing-review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive, CPU-first Rust curriculum equivalent to Stanford's CS336 language modeling course, adding structured assignments, a public content boundary, and several active, tested teaching crates. The code review feedback is highly constructive, pointing out performance optimization opportunities in the attention and mlp crates by zipping iterators directly to avoid unnecessary heap allocations. Additionally, it identifies a logical redundancy in the inference crate's temperature-scaled top-k sampling, where pre-sorted rankings make the search loop unnecessary.

Comment thread code/attention/src/lib.rs
Comment on lines +869 to +878
}

let token_values = token.values().copied().collect::<Vec<_>>();
let mut output = Vec::with_capacity(self.shape.rows().as_usize());
for row in &self.rows {
let mut sum = ProjectionOutput::zero()?;
for (component, weight) in token_values.iter().zip(row.values()) {
let product = (*component * *weight)?;
sum = (sum + product)?;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Avoid copying and collecting the vector values into a new heap-allocated Vec in project. You can zip the iterator directly to avoid unnecessary allocations.

        let mut output = Vec::with_capacity(self.shape.rows().as_usize());
        for row in &self.rows {
            let mut sum = ProjectionOutput::zero()?;
            for (component, weight) in token.values().copied().zip(row.values()) {
                let product = (component * *weight)?;
                sum = (sum + product)?;
            }
            output.push(sum);
        }

Comment thread code/mlp/src/lib.rs
Comment on lines +307 to +318
}
}

/// Hidden representation after ReLU.
#[derive(Debug, Clone, PartialEq)]
pub struct HiddenActivation(DenseVector<HiddenActivationValue>);

impl HiddenActivation {
fn from_values(
values: impl IntoIterator<Item = HiddenActivationValue>,
) -> Result<Self, MlpError> {
Ok(Self(DenseVector::from_values(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Avoid copying and collecting the vector values into a new heap-allocated Vec in multiply_input and multiply_hidden. Since DenseVector is defined in the same module, you can directly reference the inner values slice (&vector.0.values) to avoid unnecessary allocations.

    fn multiply_input(&self, vector: &InputVector) -> Result<DenseVector<WeightedSum>, MlpError> {
        self.multiply_values("WeightMatrix::multiply_input", vector.width(), &vector.0.values)
    }

    fn multiply_hidden(
        &self,
        vector: &HiddenActivation,
    ) -> Result<DenseVector<WeightedSum>, MlpError> {
        self.multiply_values("WeightMatrix::multiply_hidden", vector.width(), &vector.0.values)
    }

Comment thread code/inference/src/lib.rs
Comment on lines +357 to +379
fn try_from(value: usize) -> Result<Self, Self::Error> {
Ok(Self(nonzero_usize(
"context window must be greater than zero",
"ContextWindow::try_from",
value,
)?))
}
}

impl fmt::Display for ContextWindow {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(formatter, "{} tokens", self.0)
}
}

/// Total token budget implied by a prompt and generation request.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct TokenBudget(usize);

impl TokenBudget {
fn from_raw(operation: &'static str, value: usize) -> Result<Self, InferenceError> {
Ok(Self(nonzero_usize(
"token budget must be greater than zero",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since rankings are already sorted in descending order (via compare_ranked_tokens) and temperature is strictly positive, division by temperature preserves the relative order of the logits. Consequently, the first candidate in the iteration will always have the maximum adjusted logit, making the loop and division redundant. If deterministic selection is intended for this toy implementation, you can simplify this to directly return the first candidate.

            Self::TopK { .. } => {
                rankings.candidates()
                    .next()
                    .map(|candidate| candidate.token_id())
                    .ok_or_else(|| InferenceError::empty_input(
                        "SamplingMode::select",
                        "top-k candidate set cannot be empty",
                    ))
            }

@hghalebi
hghalebi merged commit 9587ca3 into main May 28, 2026
1 check passed
@hghalebi
hghalebi deleted the codex/add-ci-and-gemini-writing-review branch May 28, 2026 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant