Skip to content

Conversation

@SK8-infi
Copy link

@SK8-infi SK8-infi commented Jan 13, 2026

Fixes

Closes: #22

Type of Change

  • Bug fix
  • New feature
  • Documentation / Refactor
  • Math / Logic correction

Description

Implemented validation split and MLflow tracking for monitoring model generalization performance.

Changes:

  • Added validation_split: float = 0.2 parameter to Model.train() method
  • Split data into training and validation sets after preprocessing
  • Modified training loop to train epoch-by-epoch and calculate validation loss after each epoch
  • Added _calculate_validation_loss() method supporting both classification (cross-entropy) and regression (MSE)
  • Extended Rust bindings with forward() method to expose raw model outputs for validation loss calculation
  • Updated save_model() to log both loss and val_loss metrics to MLflow with epoch steps
  • Added error handling for edge cases (empty predictions, shape mismatches, small validation sets)

Result: MLflow dashboard now displays overlapping train/validation loss curves for monitoring overfitting and generalization.

How Has This Been Tested?

  • Unit Tests: Created and ran test_validation_split.py covering classification, regression, and edge cases
  • Manual Testing: Verified with dummy datasets and confirmed loss curves in MLflow
  • Integration: Confirmed Rust core forward() method works correctly with Python API
  • Existing Tests: All existing pytest tests pass

Screenshots / Logs

image image
📊 Data split: 80 training samples, 20 validation samples
Epoch 0/10 - Train Loss: 0.8602, Val Loss: 0.2851

📈 Logging 10 training metrics points...
📈 Logging 10 validation metrics points...

Contribution Context

  • I am contributing through the SWOC program.

@github-actions
Copy link

Manual Action Required!

This pull request is not yet linked to an issue. Please update the description to include 'Closes: #issue_number' in the appropriate section. This is required to pass validation and initiate metadata synchronization.

@github-actions
Copy link

Thank you for opening this PR! Our automated system is currently verifying the PR requirements.
Internal Discussion: Discord

@github-actions
Copy link

Validation Successful!

This pull request has been verified and linked to issue #22. The system is now synchronizing metadata from the referenced issue. Kindly await maintainer review of your changes.

@github-actions github-actions bot added area: python-api The user-facing Python library, Model class, and top-level CLI. feature New ML layers or API functionality. Medium Requires good codebase knowledge. labels Jan 13, 2026
@Satyamgupta2365
Copy link
Collaborator

heyy. CI is failing on test_model_save_load_preserves_preprocessing.
The validation step is producing no predictions, causing a shape mismatch (y_true (1,2) vs y_pred (0,)).
Please ensure validation data uses the same preprocessing and that predict() is correctly called for X_val, especially for small validation sizes.

@SK8-infi
Copy link
Author

heyy. CI is failing on test_model_save_load_preserves_preprocessing. The validation step is producing no predictions, causing a shape mismatch (y_true (1,2) vs y_pred (0,)). Please ensure validation data uses the same preprocessing and that predict() is correctly called for X_val, especially for small validation sizes.

Thanks @Satyamgupta2365 for review. Will keep this in mind. currently the work is in progress.

@github-actions
Copy link

Validation Successful!

This pull request has been verified and linked to issue #22. The system is now synchronizing metadata from the referenced issue. Kindly await maintainer review of your changes.

@SK8-infi SK8-infi marked this pull request as ready for review January 14, 2026 19:53
@github-actions
Copy link

Validation Successful!

This pull request has been verified and linked to issue #22. The system is now synchronizing metadata from the referenced issue. Kindly await maintainer review of your changes.

@SK8-infi
Copy link
Author

Hii @Satyamgupta2365 finished the PR from my side and is ready for review. Thanks

@SK8-infi SK8-infi changed the title [WIP] feat: Validation Split & MLflow Tracking feat: Validation Split & MLflow Tracking Jan 14, 2026
@github-actions
Copy link

Validation Successful!

This pull request has been verified and linked to issue #22. The system is now synchronizing metadata from the referenced issue. Kindly await maintainer review of your changes.

@github-actions github-actions bot added the SWoC26 Contributions specifically for the Social Winter of Code program. label Jan 14, 2026
@github-actions
Copy link

Validation Successful!

This pull request has been verified and linked to issue #22. The system is now synchronizing metadata from the referenced issue. Kindly await maintainer review of your changes.

Copy link
Contributor

@debug-soham debug-soham left a comment

Choose a reason for hiding this comment

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

@SK8-infi Thank you for the effort! While validation tracking is a great addition, this PR introduces critical architectural issues that must be addressed:

  • Optimizer State Reset: Moving the training loop to Python causes a new Adam/SGD instance to be created every epoch. This resets Adam's moment estimates and time-step to zero, breaking its adaptive logic.
  • Performance Overhead: Calling the Rust backend once per epoch significantly increases FFI marshaling and context-switching overhead.
  • Regressions: The code lacks the batch_size parameter recently merged in PR #63, which will cause build and runtime failures.

Requested Changes:

  1. Revert the Python Loop: Move the validation logic into the Rust train method so the optimizer remains persistent.
  2. Sync with Main: Update signatures to include the mandatory batch_size parameter.
  3. Preserve forward(): Keep this new method in lib.rs as it is a valuable utility.

@debug-soham
Copy link
Contributor

@SK8-infi Please update us on the status. You have 24 hours to address the issues or we’ll close this PR and reassign the task to keep development on track.

@github-actions
Copy link

Validation Successful!

This pull request has been verified and linked to issue #22. The system is now synchronizing metadata from the referenced issue. Kindly await maintainer review of your changes.

@github-actions github-actions bot requested a review from debug-soham January 20, 2026 21:59
@SK8-infi
Copy link
Author

had to do some changes in tests as the new signature is (train_losses, val_losses)

@github-actions
Copy link

Validation Successful!

This pull request has been verified and linked to issue #22. The system is now synchronizing metadata from the referenced issue. Kindly await maintainer review of your changes.

@debug-soham
Copy link
Contributor

@SK8-infi Build tests are failing.

@SK8-infi
Copy link
Author

Seems to be an issue happened during resolving conflicts. Looking into it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: python-api The user-facing Python library, Model class, and top-level CLI. feature New ML layers or API functionality. Medium Requires good codebase knowledge. SWoC26 Contributions specifically for the Social Winter of Code program.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Python] Validation Split & MLflow Tracking

3 participants