microsoft / microsoft/qlib

Bug: metric_fn in HIST and IGMTF always raises ValueError for default metric

Open Beginner friendly
#2,163 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
48.7k
Forks
7.7k
PR merge metrics
No merged PRs in 30d

Description

Description

metric_fn() in pytorch_hist.py (line 173) and pytorch_igmtf.py (line 166) uses == to compare self.metric against the tuple ("", "loss"):

if self.metric == ("", "loss"):
    return -self.loss_fn(pred[mask], label[mask])

Since self.metric is always a string (default is ""), this comparison is never true. The function falls through to raise ValueError("unknown metric").

All other models correctly use in:

# pytorch_alstm.py, pytorch_gru.py, pytorch_lstm.py, etc.
if self.metric in ("", "loss"):
    return -self.loss_fn(pred[mask], label[mask])
Impact

Any user training HIST or IGMTF with the default metric (or metric="loss") will get a crash:

ValueError: unknown metric ``
Fix
- if self.metric == ("", "loss"):
+ if self.metric in ("", "loss"):

I will submit a fix shortly.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with metric_fn in pytorch_hist.py around line 173 and pytorch_igmtf.py around line 166, then compare the corresponding implementations in pytorch_alstm.py, pytorch_gru.py, and pytorch_lstm.py. Verify that the default metric and metric="loss" paths complete without the unknown-metric error while other metric handling remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.