Skip to content

feat: add nframe=3 adsorption softmax training#5746

Draft
anyangml wants to merge 2 commits into
masterfrom
temp/property-batch-fitting
Draft

feat: add nframe=3 adsorption softmax training#5746
anyangml wants to merge 2 commits into
masterfrom
temp/property-batch-fitting

Conversation

@anyangml

@anyangml anyangml commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings July 7, 2026 04:27
@anyangml anyangml marked this pull request as draft July 7, 2026 04:27
@dosubot dosubot Bot added the new feature label Jul 7, 2026
@github-actions github-actions Bot added the Python label Jul 7, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a softmax-weighted averaging behavior intended for an adsorption workflow that uses exactly 3 frames/samples per batch, and adjusts HDF5 opening behavior.

Changes:

  • Open HDF5 files with locking=False in the cached H5 loader.
  • Add softmax-weighted averaging across the batch in PyTorch PropertyLoss and enforce nbz == 3.
  • Add softmax-weighted averaging across frames in DeepProperty.eval and enforce nframes == 3 (with a debug print).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
deepmd/utils/path.py Changes HDF5 file open behavior by disabling file locking.
deepmd/pt/loss/property.py Introduces batch-level softmax averaging and hard-codes a batch size of 3 in the property loss.
deepmd/infer/deep_property.py Introduces frame-level softmax averaging and hard-codes nframes == 3 (plus debug output).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread deepmd/utils/path.py
Comment on lines 331 to +334
# this method has cache to avoid duplicated
# loading from different DPH5Path
# However the file will be never closed?
return h5py.File(path, mode)
return h5py.File(path, mode, locking=False)
Comment on lines +103 to +122
# ---- Softmax-weighted averaging over the batch added by YL----
# model_pred[var_name]: (nbz, task_dim)
# 1) get a scalar score per sample (mean over task_dim)
# (If you want to favor smaller values, use `score_per_sample = -model_pred[var_name].mean(dim=1)`.)
score_per_sample = model_pred[var_name].mean(dim=1) # (nbz,)
weights = F.softmax(score_per_sample, dim=0) # (nbz,)
# 2) weighted average vector (1, task_dim)
avg_vec = (weights.unsqueeze(1) * model_pred[var_name]).sum(dim=0, keepdim=True)
# 3) replace all predictions with the averaged vector (broadcast over batch)
model_pred[var_name] = avg_vec.expand_as(model_pred[var_name])
# ----------------------------------------------------

nbz = model_pred[var_name].shape[0]
# =======Raise error when nbz!=3=======
if nbz != 3:
raise RuntimeError(
f"[PropertyLoss] Expected batch size nbz == 3 for softmax-avg, got nbz == {nbz}. "
"Ensure your DataLoader yields triples (batch_size=3, drop_last=True)."
)

Comment on lines +144 to +153
# --- softmax-weighted averaging over frames (minimal) ---
print(f"Nframes == {nframes}")
if nframes != 3:
raise RuntimeError(f"Expected nframes == 3, got {nframes}")
scores = property.mean(axis=1) # (3,)
# If you want to favor *smaller* values (e.g., energies), use: scores = -scores
w = np.exp(scores - scores.max())
w /= w.sum() # (3,)
avg = (w[:, None] * property).sum(axis=0, keepdims=True) # (1, D)
property[:] = np.repeat(avg, nframes, axis=0) # (3, D)
@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 4.54545% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.02%. Comparing base (8787b45) to head (0c77220).
⚠️ Report is 306 commits behind head on master.

Files with missing lines Patch % Lines
deepmd/pt/loss/property.py 0.00% 13 Missing ⚠️
deepmd/infer/deep_property.py 0.00% 8 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (8787b45) and HEAD (0c77220). Click for more details.

HEAD has 32 uploads less than BASE
Flag BASE (8787b45) HEAD (0c77220)
56 24
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5746      +/-   ##
==========================================
- Coverage   81.95%   76.02%   -5.94%     
==========================================
  Files         714     1015     +301     
  Lines       73441   139629   +66188     
  Branches     3616     5764    +2148     
==========================================
+ Hits        60187   106146   +45959     
- Misses      12091    31831   +19740     
- Partials     1163     1652     +489     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants