Skip to content

Harden trainer edge cases, vectorize input mapping, and unify pytest configuration#25

Merged
theomgdev merged 3 commits intomainfrom
copilot/fix-bugs-performance-issues
Apr 14, 2026
Merged

Harden trainer edge cases, vectorize input mapping, and unify pytest configuration#25
theomgdev merged 3 commits intomainfrom
copilot/fix-bugs-performance-issues

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 13, 2026

Summary

This PR addresses concrete quality issues by tightening trainer/runtime invariants, removing hot-path inefficiencies in input preparation, and resolving config drift between pytest config files. Scope is surgical: correctness under edge conditions, lower per-step overhead, and cleaner project structure.

Changes

  • Trainer safety invariants

    • Validate gradient_accumulation_steps in train_batch (int and >= 1).
    • Validate fit inputs early:
      • batch_size >= 1
      • non-empty dataset
      • input_features / target_values length match.
  • Input pipeline performance

    • Replaced per-feature Python loops in prepare_input with vectorized indexed assignment for 2D and 3D cases.
  • Test/config alignment

    • Added trainer tests for invalid accumulation steps, empty dataset, length mismatch, and invalid batch size.
    • Removed duplicate pytest config from pyproject.toml so pytest.ini remains the single source of truth.
# before: O(num_assigned) Python loop
for k in range(num_assigned):
    x_input[:, model_input_ids[k]] = input_features[:, k]

# after: vectorized assignment
target_ids = model_input_ids[:num_assigned]
x_input[:, target_ids] = input_features[:, :num_assigned]

Checklist

All contributions

  • Code follows the project conventions (see CONTRIBUTING.md)
  • Tests pass (python -m pytest tests/or pytest tests/)
  • No sys.path.append hacks — imports use from odyssnet import ... directly

Library changes (odyssnet/)

  • Corresponding test added/updated under tests/
  • Documentation updated in relevant markdown files (LIBRARY.md, CONTRIBUTING.md)

New/modified example scripts (examples/)

  • set_seed(42) is called as the first line of main()
  • Placed in correct folder (examples/ for core validations, examples/advanced/ for complex tasks)
  • Uses OdyssNetTrainer (not a manual training loop)
  • Uses TrainingHistory to record metrics and calls history.plot() at the end
  • File paths are relative to __file__, not hardcoded

@theomgdev theomgdev marked this pull request as ready for review April 13, 2026 23:23
Copilot AI review requested due to automatic review settings April 13, 2026 23:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR tightens trainer input/runtime invariants, reduces per-step overhead in the input preparation path by vectorizing feature-to-neuron mapping, and removes duplicated pytest configuration to avoid config drift.

Changes:

  • Added early validation in OdyssNetTrainer.train_batch() and fit() for common invalid/edge-case inputs.
  • Vectorized prepare_input() feature assignment for both 2D and 3D inputs.
  • Added regression tests for the new trainer invariants and removed duplicate pytest config from pyproject.toml.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
odyssnet/training/trainer.py Adds early validation for gradient_accumulation_steps, batch_size, and dataset shape invariants.
odyssnet/utils/data.py Replaces per-feature Python loops with vectorized indexed assignment in prepare_input().
tests/training/test_trainer.py Adds tests covering invalid accumulation steps, empty dataset, length mismatch, and invalid batch size.
pyproject.toml Removes [tool.pytest.ini_options] so pytest.ini is the single source of truth.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread odyssnet/training/trainer.py Outdated
Comment thread odyssnet/training/trainer.py
theomgdev and others added 2 commits April 14, 2026 03:40
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@theomgdev theomgdev merged commit fb5fdeb into main Apr 14, 2026
6 checks passed
@theomgdev theomgdev deleted the copilot/fix-bugs-performance-issues branch April 14, 2026 00:40
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.

3 participants