Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to apply mean to energy #818

Merged
merged 6 commits into from
Aug 22, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/fairchem/core/models/equiformer_v2/equiformer_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,9 @@ def no_weight_decay(self) -> set:

@registry.register_model("equiformer_v2_energy_head")
class EquiformerV2EnergyHead(nn.Module, HeadInterface):
def __init__(self, backbone):
def __init__(self, backbone, reduce: str="sum"):
super().__init__()

self.reduce = reduce
self.avg_num_nodes = backbone.avg_num_nodes
self.energy_block = FeedForwardNetwork(
backbone.sphere_channels,
Expand All @@ -638,8 +638,15 @@ def forward(self, data: Batch, emb: dict[str, torch.Tensor | GraphData]):
device=node_energy.device,
dtype=node_energy.dtype,
)

energy.index_add_(0, data.batch, node_energy.view(-1))
return {"energy": energy / self.avg_num_nodes}
if self.reduce == "sum":
return {"energy": energy / self.avg_num_nodes}
wood-b marked this conversation as resolved.
Show resolved Hide resolved
elif self.reduce == "mean":
return {"energy": energy / data.natoms}
else:
raise ValueError(f"agg_fn can only be sum or mean, user provided: {self.agg_fn}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

forgot to switch this agg_fn to reduce

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

opps




@registry.register_model("equiformer_v2_force_head")
Expand Down