Skip to content

New azure log refactor - #154

Open
kirilklein wants to merge 5 commits into
mainfrom
fix/log_azure_pipeline
Open

New azure log refactor#154
kirilklein wants to merge 5 commits into
mainfrom
fix/log_azure_pipeline

Conversation

@kirilklein

@kirilklein kirilklein commented Jul 23, 2025

Copy link
Copy Markdown
Owner

…ndling

  • Updated logging functions to utilize MLFLOW_CLIENT for metric, parameter, and image logging.
  • Enhanced prefix handling for metrics and parameters to ensure proper naming conventions.
  • Improved run handling logic to correctly traverse parent runs and build prefixes.
  • Refactored function signatures for consistency and clarity.

Summary by CodeRabbit

  • New Features

    • Improved logging functions for metrics, parameters, images, and figures, allowing for more flexible input formats and consistent prefixing of keys and artifact paths.
    • Enhanced MLflow run management with support for nested runs and run naming during job execution.
    • Added automatic logging of validation and test metrics, as well as training and validation losses, with configurable limits on the number of targets logged.
  • Bug Fixes

    • Enhanced exception handling for external library imports.
  • Refactor

    • Updated function signatures for logging utilities to accept dictionaries and objects directly, streamlining the logging process.

…ndling

* Updated logging functions to utilize MLFLOW_CLIENT for metric, parameter, and image logging.
* Enhanced prefix handling for metrics and parameters to ensure proper naming conventions.
* Improved run handling logic to correctly traverse parent runs and build prefixes.
* Refactored function signatures for consistency and clarity.
@coderabbitai

coderabbitai Bot commented Jul 23, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes refactor logging utilities for MLflow integration by improving exception handling, modifying function signatures, and ensuring consistent prefixing of keys and artifact paths. All logging functions now use the MLFLOW_CLIENT instance with explicit run IDs, and function parameters have been updated for clarity and consistency. Additionally, MLflow run initialization in the job runner was enhanced to support nested runs with explicit naming. A new block was added to log validation and test metrics during training in the causal trainer module.

Changes

Cohort / File(s) Change Summary
MLflow Logging Utilities Refactor
corebehrt/azure/util/log.py
Refactored MLflow logging utilities: improved exception handling for imports, changed parent run traversal logic, updated all logging functions to use MLFLOW_CLIENT with explicit run IDs, revised function signatures, and standardized prefix application.
MLflow Run Initialization Enhancement
corebehrt/azure/util/job.py
Modified run_main to check MLflow availability and active run status before starting a run, enabling nested runs and setting run names explicitly during job execution.
Training Metrics Logging Addition
corebehrt/modules/trainer/causal/trainer.py
Added MLflow logging of validation and test metrics, and training and validation losses within validate_and_log method, with configurable limits on the number of targets logged per epoch.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Merge/april1 #47: Directly related by changes to corebehrt/azure/util/log.py including get_run_and_prefix and logging function signatures and implementations using MLflow client instance.
  • Logging #54: Related by modifications to logging function signatures and implementations in corebehrt/azure/util/log.py, focusing on simplifying log_param function signature and calls.

Poem

In the warren where logs abound,
A rabbit tweaks the code all around.
Prefixes hop to each metric and param,
With MLflow’s client, it’s never a jam.
No more generic excepts to fear—
Just tidy runs, all crystal clear!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4e5013a and eeb5a4a.

📒 Files selected for processing (1)
  • corebehrt/modules/trainer/causal/trainer.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: tests
  • GitHub Check: pipeline_tests_performance
  • GitHub Check: test
  • GitHub Check: pipeline_tests
  • GitHub Check: tests
  • GitHub Check: tests
  • GitHub Check: Test Coverage
  • GitHub Check: unittests
  • GitHub Check: tests
  • GitHub Check: tests
  • GitHub Check: Docstring Coverage
🔇 Additional comments (1)
corebehrt/modules/trainer/causal/trainer.py (1)

567-585: MLflow logging integration verified – no critical issues found.

  • The run_log method is defined in corebehrt/modules/trainer/trainer.py (lines 481–485), so the logging calls will work as expected.
  • As an optional enhancement, you may prioritize key metrics (e.g., AUC, loss, accuracy) before hitting the self.num_targets_to_log limit to ensure the most important metrics are always logged.
  • You could also wrap the MLflow calls in a try/except block to guard against intermittent logging failures without interrupting training.

Optional metric-prioritization example:

 # Log all validation metrics
 if val_metrics:
-    for i, (metric_name, value) in enumerate(val_metrics.items()):
-        if i >= self.num_targets_to_log:
-            break
-        self.run_log(f"val_{metric_name}", value, step=epoch)
+    priority = [m for m in val_metrics if any(k in m for k in ['auc','loss','accuracy'])]
+    others   = [m for m in val_metrics if m not in priority]
+    count = 0
+    for name in priority + others:
+        if count >= self.num_targets_to_log:
+            break
+        self.run_log(f"val_{name}", val_metrics[name], step=epoch)
+        count += 1

Optional error handling example:

try:
    self.run_log("train_loss", avg_train_loss, step=epoch)
    if val_loss is not None:
        self.run_log("val_loss", val_loss, step=epoch)
except Exception as e:
    self.log(f"MLflow logging failed: {e}")
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/log_azure_pipeline

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@kirilklein
kirilklein marked this pull request as ready for review August 4, 2025 09:50
@kirilklein

Copy link
Copy Markdown
Owner Author

running a check currently

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