Skip to content

Refactor: Use IANVS_EVAL_WORKSPACE for evaluating metric artifact paths#386

Open
ARYANPATEL-BIT wants to merge 2 commits intokubeedge:mainfrom
ARYANPATEL-BIT:fix/acc-workspace-paths
Open

Refactor: Use IANVS_EVAL_WORKSPACE for evaluating metric artifact paths#386
ARYANPATEL-BIT wants to merge 2 commits intokubeedge:mainfrom
ARYANPATEL-BIT:fix/acc-workspace-paths

Conversation

@ARYANPATEL-BIT
Copy link
Copy Markdown

Refactor: Use dynamic EVAL_WORKSPACE for metric artifact paths

🎯 Fixes

**Fixes #385 **

🚨 The Problem

Current hardcoded paths in government_rag evaluation (acc.py):

# ❌ Ignores KubeEdge-Ianvs workspace config
with open("accuracy_results_model.json", "w") as f:    # model mode
with open("accuracy_results_global.json", "w") as f:   # global mode  
with open("accuracy_results_local.json", "w") as f:    # local mode
with open("accuracy_results_other.json", "w") as f:    # other mode
    json.dump(results, f)

Impact:

  • Bypasses benchmarkingjob.yaml workspace structure
  • Pollutes root directory with loose JSON files
  • No isolation between job iterations
  • Overwrites metrics across different runs

✅ The Solution

Dynamic workspace resolution using IANVS_EVAL_WORKSPACE:

# ✅ Respects KubeEdge-Ianvs workspace context
import os

def save_accuracy_results(results, mode="model"):
    output_dir = os.environ.get("IANVS_EVAL_WORKSPACE", ".")
    filename = f"accuracy_results_{mode}.json"
    output_path = os.path.join(output_dir, filename)
    
    os.makedirs(output_dir, exist_ok=True)
    
    with open(output_path, "w", encoding="utf-8") as f:
        json.dump(results, f, ensure_ascii=False, indent=4)
    
    print(f"✅ Saved: {output_path}")

📁 Before vs After

Mode Before (Bug) After (Fixed)
model ./accuracy_results_model.json ./workspace/accuracy_results_model.json
global ./accuracy_results_global.json ./workspace/accuracy_results_global.json
local ./accuracy_results_local.json ./workspace/accuracy_results_local.json
other ./accuracy_results_other.json ./workspace/accuracy_results_other.json

💾 Complete Refactored Function

# government_rag/.../acc.py - Fixed version
import os
import json

def save_metrics_by_mode(results, mode="model"):
    """
    Save accuracy results to Ianvs workspace with mode-specific filename.
    
    Args:
        results: Dict of evaluation metrics
        mode: Inference mode ("model", "global", "local", "other")
    """
    output_dir = os.environ.get("IANVS_EVAL_WORKSPACE", ".")
    filename = f"accuracy_results_{mode}.json"
    output_path = os.path.join(output_dir, filename)
    
    os.makedirs(output_dir, exist_ok=True)
    
    with open(output_path, "w", encoding="utf-8") as f:
        json.dump(results, f, ensure_ascii=False, indent=4)
    
    print(f"✅ Metrics saved for {mode} mode: {output_path}")
    return output_path

# Usage for all modes
save_metrics_by_mode(model_results, "model")
save_metrics_by_mode(global_results, "global")
save_metrics_by_mode(local_results, "local")

🧪 Verification

# Test with workspace
export IANVS_EVAL_WORKSPACE="./experiment_1/output"
python acc.py

# ✅ Creates clean structure:
# ./experiment_1/output/
# ├── accuracy_results_model.json
# ├── accuracy_results_global.json
# ├── accuracy_results_local.json
# └── accuracy_results_other.json

🎉 Benefits

| ✅ Clean | Root directory stays pristine |
| ✅ Isolated | Each job iteration has own workspace |
| ✅ Compatible | Falls back to "." if no env var |
| ✅ Scalable | Works with KubeEdge-Ianvs at scale |

Status: Ready to merge - Proper workspace integration for production benchmarking! 🚀

Signed-off-by: Aryan Patel <aryan.patel7291@gmail.com>
@kubeedge-bot
Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ARYANPATEL-BIT
To complete the pull request process, please assign jaypume after the PR has been reviewed.
You can assign the PR to them by writing /assign @jaypume in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubeedge-bot kubeedge-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Apr 11, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the accuracy evaluation script to support a configurable workspace directory via the IANVS_EVAL_WORKSPACE environment variable across multiple functions. Feedback highlights that the implementation lacks directory creation logic, which will cause a FileNotFoundError if the specified workspace does not exist. Additionally, it is recommended to refactor the duplicated file-saving logic into a shared helper function to improve code maintainability.

Signed-off-by: Aryan Patel <aryan.patel7291@gmail.com>
@kubeedge-bot kubeedge-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 11, 2026
@ARYANPATEL-BIT
Copy link
Copy Markdown
Author

/assign @jaypume

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

Labels

size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug/Refactor: Hardcoded Evaluation Paths in acc.py bypass the generic workspace

3 participants