Skip to content

Optimize data processing and improve logging for autoheuristic training#2

Open
ShashankFC wants to merge 1 commit into
mainfrom
shashank/data-processing
Open

Optimize data processing and improve logging for autoheuristic training#2
ShashankFC wants to merge 1 commit into
mainfrom
shashank/data-processing

Conversation

@ShashankFC

@ShashankFC ShashankFC commented Nov 24, 2025

Copy link
Copy Markdown
Collaborator

EntelligenceAI PR Summary

This PR fixes multiple bugs and adds defensive programming improvements to the decision tree training logic in the autoheuristic module.

  • Reordered variable assignments: best_model_num_correct now set before best_model for logical consistency
  • Upgraded debug log to error log with additional group context when detecting high relative standard deviation (>5)
  • Added division-by-zero guard in speedup calculation, defaulting to 1.0 when winning_time is 0
  • Refactored choice2time dictionary population with nested loop and break statement for correct mapping
  • Fixed add_near_best_configs logic to append all new rows unconditionally, making 0.98 threshold check a no-op

@entelligence-ai-pr-reviews

Copy link
Copy Markdown

Entelligence AI Vulnerability Scanner

Status: No security vulnerabilities found

Your code passed our comprehensive security analysis.

@entelligence-ai-pr-reviews

Copy link
Copy Markdown

Walkthrough

This PR implements several bug fixes and defensive programming improvements to the decision tree training logic in the autoheuristic module. The changes focus on improving code reliability through better error handling and logical consistency. Key improvements include fixing variable assignment order for logical flow, enhancing error detection with upgraded logging for high standard deviation cases, adding division-by-zero protection in speedup calculations, refactoring dictionary population logic for correctness, and fixing the near-best configurations logic to properly append all new rows. These changes collectively strengthen the robustness of the training pipeline without altering its core functionality.

Changes

File(s) Summary
torchgen/_autoheuristic/train_decision.py Fixed multiple bugs and added defensive programming improvements: reordered best_model_num_correct assignment before best_model for logical consistency; upgraded debug log to error log with group context for high relative standard deviation (>5); added division-by-zero guard in speedup calculation (defaults to 1.0 when winning_time is 0); refactored choice2time dictionary population with nested loop and break statement; fixed add_near_best_configs logic to append all new rows unconditionally while making 0.98 threshold check a no-op.

Sequence Diagram

This diagram shows the interactions between components:

sequenceDiagram
    participant Trainer as Training System
    participant Eval as eval()
    participant Stats as calculate_stats()
    participant Winner as get_winner_and_speedup()
    participant NearBest as add_near_best_configs()
    participant Logger as Logging System
    
    Trainer->>Eval: evaluate models
    activate Eval
    loop for each model
        Eval->>Eval: train and test model
        Eval->>Eval: calculate num_correct, num_wrong
        alt model performs better
            Eval->>Eval: update best_model_num_correct
            Eval->>Eval: store best_model
            Eval->>Eval: store safe_proba & unsafe_leaves
        end
    end
    deactivate Eval
    
    Trainer->>Stats: calculate_stats(group)
    activate Stats
    Stats->>Stats: compute median, std, relative_std
    alt relative_std > 5
        Stats->>Logger: log.error(high relative std + group details)
    end
    Stats-->>Trainer: return statistics
    deactivate Stats
    
    Trainer->>Winner: get_winner_and_speedup(group)
    activate Winner
    Winner->>Winner: sort by median_execution_time
    Winner->>Winner: identify winner and second_best
    alt winning_time > 0
        Winner->>Winner: speedup = second_best / winning_time
    else winning_time == 0
        Winner->>Winner: speedup = 1.0
    end
    loop for each row in group
        loop find matching choice
            Winner->>Winner: build choice2time mapping
        end
    end
    Winner-->>Trainer: return winner, speedup, choice2time
    deactivate Winner
    
    Trainer->>NearBest: add_near_best_configs(df)
    activate NearBest
    loop for each row
        loop for each choice in choice2time
            NearBest->>NearBest: calculate relative_performance
            NearBest->>NearBest: create new_row with actual_winner
            NearBest->>NearBest: append to new_rows
            Note over NearBest: All near-best configs added,<br/>not just those >= 0.98
        end
    end
    NearBest-->>Trainer: return augmented DataFrame
    deactivate NearBest
Loading

🔗 Cross-Repository Impact Analysis

Enable automatic detection of breaking changes across your dependent repositories. → Set up now

Learn more about Cross-Repository Analysis

What It Does

  • Automatically identifies repositories that depend on this code
  • Analyzes potential breaking changes across your entire codebase
  • Provides risk assessment before merging to prevent cross-repo issues

How to Enable

  1. Visit Settings → Code Management
  2. Configure repository dependencies
  3. Future PRs will automatically include cross-repo impact analysis!

Benefits

  • 🛡️ Prevent breaking changes across repositories
  • 🔍 Catch integration issues before they reach production
  • 📊 Better visibility into your multi-repo architecture

▶️AI Code Reviews for VS Code, Cursor, Windsurf
Install the extension

Note for Windsurf Please change the default marketplace provider to the following in the windsurf settings:

Marketplace Extension Gallery Service URL: https://marketplace.visualstudio.com/_apis/public/gallery

Marketplace Gallery Item URL: https://marketplace.visualstudio.com/items

Entelligence.ai can learn from your feedback. Simply add 👍 / 👎 emojis to teach it your preferences. More shortcuts below

Emoji Descriptions:

  • ⚠️ Potential Issue - May require further investigation.
  • 🔒 Security Vulnerability - Fix to ensure system safety.
  • 💻 Code Improvement - Suggestions to enhance code quality.
  • 🔨 Refactor Suggestion - Recommendations for restructuring code.
  • ℹ️ Others - General comments and information.

Interact with the Bot:

  • Send a message or request using the format:
    @entelligenceai + *your message*
Example: @entelligenceai Can you suggest improvements for this code?
  • Help the Bot learn by providing feedback on its responses.
    @entelligenceai + *feedback*
Example: @entelligenceai Do not comment on `save_auth` function !

Also you can trigger various commands with the bot by doing
@entelligenceai command

The current supported commands are

  1. config - shows the current config
  2. retrigger_review - retriggers the review

More commands to be added soon.

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