Skip to content

fairchem model relaxations crash from .cpu().numpy() on grad tensors #469

@janosh

Description

@janosh

torch_sim.models.fairchem.FairChemModel.forward() converts tensors to numpy without detaching first. during structure relaxation these tensors can require grad, so .cpu().numpy() raises:

RuntimeError: can't call numpy() on Tensor that requires grad

fix in torch_sim/models/fairchem.py: use .detach().cpu().numpy() for: positions, atomic_numbers, pbc, row_vector_cell

tests/models/test_fairchem.py calls model(state) directly, but does not run ts.optimize(...) / lbfgs. the failure only appears in relax/optimizer flow where state.positions can require grad.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions