Skip to content

[Code scan] Fix diff_on eigenvalue loss indexing for 2D band tensors #357

Description

@njzjz

This issue is part of a Codex global repository scan.

Problem:
EigLoss.forward asserts that eig_pred_cut and eig_label_cut are 2D tensors, but the diff_on branch indexes them as if they were 3D ([:, k_diff_i, :]).

Code references:
https://github.com/deepmodeling/deeptb/blob/86c60c73996f0dd961c3138f2e88424382cb734e/dptb/nnops/loss.py#L188-L193
https://github.com/deepmodeling/deeptb/blob/86c60c73996f0dd961c3138f2e88424382cb734e/dptb/nnops/loss.py#L223-L237

Impact:
Any run with diff_on=True raises an indexing error instead of computing the differential eigenvalue loss.

Suggested fix:
Index the k-point dimension consistently for 2D tensors, for example eig_label_cut[k_diff_i, :] - eig_label_cut[k_diff_j, :], with the same correction for predictions and masked variants.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions