Skip to content

Chore/add loss column - #42

Merged
fengzz-coding merged 11 commits into
mainfrom
chore/add_loss_column
Nov 27, 2025
Merged

Chore/add loss column#42
fengzz-coding merged 11 commits into
mainfrom
chore/add_loss_column

Conversation

@fengzz-coding

@fengzz-coding fengzz-coding commented Nov 11, 2025

Copy link
Copy Markdown
Collaborator

add raw loss column

Summary by CodeRabbit

  • New Features

    • Implemented raw loss metric tracking to surface an additional validation metric for better performance monitoring and scoring analysis.
  • Tests

    • Updated validator tests to expect and validate the new raw loss field in stored validator metrics.

@coderabbitai

coderabbitai Bot commented Nov 11, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Added a new REAL column raw_loss to miner_scores, implemented ScoreDB.update_raw_loss(uid, loss) to persist it, and updated the validator to call this method after evaluating miner loss.

Changes

Cohort / File(s) Summary
Database schema & API
flockoff/validator/database.py
Added raw_loss REAL to miner_scores in _init_db. Implemented ScoreDB.update_raw_loss(uid: int, loss: float) which runs UPDATE miner_scores SET raw_loss = ? WHERE uid = ?, logs a warning if no rows affected, commits on success, and raises/logs DatabaseError on sqlite3 errors.
Validator integration
neurons/validator.py
After computing/storing the raw evaluation score, added call score_db.update_raw_loss(uid, eval_loss) to persist the raw loss.
Tests updated
tests/FlockDataset/validators/test_database.py
Test expectation updated to include raw_loss in the miner_scores table column set.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Validator
    participant ScoreDB
    participant SQLite

    Validator->>ScoreDB: save_raw_score(uid, raw_score)
    ScoreDB->>SQLite: INSERT/UPDATE miner_scores (raw_score, ...)
    SQLite-->>ScoreDB: OK
    ScoreDB-->>Validator: ack

    Note over Validator,ScoreDB: New step to persist raw loss
    Validator->>ScoreDB: update_raw_loss(uid, eval_loss)
    rect rgba(0,128,96,0.08)
        ScoreDB->>SQLite: UPDATE miner_scores SET raw_loss = ? WHERE uid = ?
        alt rows_updated > 0
            SQLite-->>ScoreDB: OK (rows affected)
            ScoreDB-->>Validator: success
        else no rows updated
            SQLite-->>ScoreDB: OK (0 rows)
            ScoreDB-->>Validator: warning (no such uid)
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Verify DB migration/initialization adds raw_loss reliably across existing DB states.
  • Check SQL syntax, transaction/commit behavior, and that exceptions map to existing DatabaseError handling.
  • Confirm validator invokes update_raw_loss with correct value and error handling/logging consistency.
  • Review updated test to ensure it properly asserts schema and doesn't mask migration issues.

Poem

🐰 In a burrow of bytes I hop and peep,
A tiny column now learns to keep,
Raw loss tucked in rows so neat,
Validator hops and makes data complete,
Hooray — metrics hum, the database sleeps sweet. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Chore/add loss column' accurately describes the main change: adding a raw_loss column to the database schema and related functionality.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/add_loss_column

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
flockoff/validator/database.py (1)

158-171: Consider using logging.exception for better error diagnostics.

The implementation correctly mirrors the pattern of update_raw_eval_score. However, using logging.error in the except block (line 170) omits the stack trace. Consider using logging.exception instead for easier debugging.

Apply this diff:

         except sqlite3.Error as e:
-            logger.error(f"Failed to update raw_loss for UID {uid}: {str(e)}")
+            logger.exception(f"Failed to update raw_loss for UID {uid}: {str(e)}")
             raise DatabaseError(f"Failed to update raw_loss: {str(e)}") from e

Optional: The update_raw_loss and update_raw_eval_score methods are nearly identical. In the future, consider extracting a generic _update_column helper to reduce code duplication.

Based on static analysis hints.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1aa98d5 and 9678f3c.

📒 Files selected for processing (2)
  • flockoff/validator/database.py (2 hunks)
  • neurons/validator.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
neurons/validator.py (1)
flockoff/validator/database.py (1)
  • update_raw_loss (158-171)
🪛 Ruff (0.14.4)
flockoff/validator/database.py

170-170: Use logging.exception instead of logging.error

Replace with exception

(TRY400)


170-170: Use explicit conversion flag

Replace with conversion flag

(RUF010)


171-171: Avoid specifying long messages outside the exception class

(TRY003)


171-171: Use explicit conversion flag

Replace with conversion flag

(RUF010)

🔇 Additional comments (2)
neurons/validator.py (1)

503-504: Verify the need for storing the same value in two columns.

Both update_raw_eval_score and update_raw_loss are called with the identical eval_loss value, resulting in redundant storage in the raw_score and raw_loss columns. Unless there's a future plan for these metrics to diverge, this creates unnecessary data duplication and potential maintenance overhead.

Consider clarifying:

  • Is there a semantic difference intended between raw_score and raw_loss?
  • Will these values be computed differently in future updates?
  • If not, should one of these calls be removed?
flockoff/validator/database.py (1)

42-42: LGTM!

The column addition follows the existing pattern using _add_column_if_not_exists, ensuring backward compatibility with existing databases.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9678f3c and d78ddd4.

📒 Files selected for processing (1)
  • tests/FlockDataset/validators/test_database.py (1 hunks)

c.execute("PRAGMA table_info(miner_scores)")
columns = {row[1] for row in c.fetchall()}
expected_columns = {"uid", "hotkey", "raw_score", "normalized_score", "namespace", "revision"}
expected_columns = {"uid", "hotkey", "raw_score", "normalized_score", "namespace", "revision", "raw_loss"}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add test coverage for the new raw_loss functionality.

While the schema validation is correctly updated, there are no tests for the new update_raw_loss method mentioned in the PR summary. Following the existing test pattern in this file (e.g., test_update_raw_eval_score, test_get_raw_eval_score), you should add:

  1. test_update_raw_loss - to verify updating raw_loss for UIDs
  2. test_get_raw_loss - if a getter method exists

Would you like me to generate test cases following the established patterns in this file?

🤖 Prompt for AI Agents
In tests/FlockDataset/validators/test_database.py around line 21, the test suite
added the new raw_loss column but lacks tests for the new update_raw_loss/getter
behavior; add two tests mirroring existing patterns: (1) test_update_raw_loss —
create a test dataset/fixture, call the dataset.update_raw_loss(uid, value) for
one or more UIDs, then query the DB (or use existing helper like
get_raw_eval_score pattern) to assert the raw_loss column was updated to
expected values and that other rows remained unchanged; (2) test_get_raw_loss —
insert known raw_loss values (or use update_raw_loss), call the
dataset.get_raw_loss(uid) getter and assert it returns the expected numeric
values and handles missing UIDs appropriately; use the same fixtures,
setup/teardown and assertion styles as
test_update_raw_eval_score/test_get_raw_eval_score in this file.

@fengzz-coding
fengzz-coding merged commit 1460549 into main Nov 27, 2025
1 check passed
@fengzz-coding
fengzz-coding deleted the chore/add_loss_column branch November 28, 2025 03:50
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.

2 participants