Skip to content

Conversation

@OutisLi
Copy link
Collaborator

@OutisLi OutisLi commented Nov 18, 2025

Summary by CodeRabbit

  • New Features

    • Added type-embedding compression with an option to precompute and cache embeddings when compression is enabled.
  • Behavioral Improvements

    • Descriptor evaluation now prefers cached type embeddings to reduce repeated computation, with fallbacks to on-the-fly computation.
  • Tests

    • Unit tests updated to verify propagation and presence of precomputed type-embedding data.

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings November 18, 2025 14:45
Copilot finished reviewing on behalf of OutisLi November 18, 2025 14:49
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 18, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Adds type-embedding precomputation and caching to the SE-Attention descriptor (DescrptBlockSeAtten) and invokes that precomputation from DPA1 and DPA2 compression setup. Forward in strip mode prefers cached type embeddings when present. Tests updated to expect the new cache marker.

Changes

Cohort / File(s) Summary
DPA compression hooks
deepmd/pt/model/descriptor/dpa1.py, deepmd/pt/model/descriptor/dpa2.py
Call type_embedding_compression(self.type_embedding) from enable_compression (after existing compression setup) to trigger SE-Attention type-embedding precomputation before setting compress flags.
SE-Attention type-embedding compression
deepmd/pt/model/descriptor/se_atten.py
Import TypeEmbedNet; add type_embedding_compression(type_embedding_net) method and public buffer type_embd_data; precompute/cache one-side and two-side type embeddings; forward (strip mode) uses type_embd_data when present with fallbacks to on-the-fly embedding.
Tests: descriptor state translation
source/tests/pt/model/test_descriptor_dpa1.py, source/tests/pt/model/test_descriptor_dpa2.py
Update state save/load test logic and translation helpers to include and assert *.type_embd_data flags in translated state dictionaries alongside existing compress flags.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as enable_compression()
    participant DPA as DPA1/DPA2
    participant SE as DescrptBlockSeAtten
    rect rgba(200,230,255,0.35)
      Caller->>DPA: enable_compression()
      DPA->>SE: se_atten.enable_compression(...)
      SE->>SE: type_embedding_compression(TypeEmbedNet)
      SE-->>SE: precompute embeddings -> store in type_embd_data
      SE-->>DPA: return
      DPA->>Caller: set compress flag
    end

    rect rgba(220,255,220,0.25)
      participant Forward as forward(mode="strip")
      Caller->>Forward: forward(input, mode="strip")
      alt type_embd_data present
        Forward->>SE: use cached type_embd_data for embedding lookup
      else
        Forward->>SE: compute embeddings on-the-fly via TypeEmbedNet
      end
      SE-->>Forward: descriptor outputs
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Pay attention to one-side vs two-side precomputation indexing and ordering.
  • Verify buffer allocation/registration (device/dtype) and behavior across device moves and save/load.
  • Confirm forward fallback preserves previous semantics when cache absent.
  • Check tests and translation helpers correctly reflect the new type_embd_data flag without brittle assumptions.

Possibly related PRs

Suggested reviewers

  • njzjz
  • wanghan-iapcm
  • iProzd

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 17.50% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately reflects the main change: implementing type embedding compression for the se_atten module, which is the core feature across all modified files.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c1465d7 and c35082d.

📒 Files selected for processing (1)
  • source/tests/pt/model/test_descriptor_dpa1.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • source/tests/pt/model/test_descriptor_dpa1.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (29)
  • GitHub Check: Test C++ (false)
  • GitHub Check: Test C++ (true)
  • GitHub Check: Build wheels for cp311-macosx_arm64
  • GitHub Check: Build wheels for cp311-macosx_x86_64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build wheels for cp311-win_amd64
  • GitHub Check: Build wheels for cp310-manylinux_aarch64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Analyze (c-cpp)
  • GitHub Check: Analyze (python)
  • GitHub Check: Build C++ (clang, clang)
  • GitHub Check: Build C++ (rocm, rocm)
  • GitHub Check: Build C++ (cuda120, cuda)
  • GitHub Check: Build C++ (cuda, cuda)
  • GitHub Check: Build C++ (cpu, cpu)
  • GitHub Check: Build C library (2.18, libdeepmd_c.tar.gz)
  • GitHub Check: Build C library (2.14, >=2.5.0,<2.15, libdeepmd_c_cu11.tar.gz)
  • GitHub Check: Test Python (4, 3.9)
  • GitHub Check: Test Python (3, 3.12)
  • GitHub Check: Test Python (6, 3.9)
  • GitHub Check: Test Python (2, 3.12)
  • GitHub Check: Test Python (6, 3.12)
  • GitHub Check: Test Python (1, 3.9)
  • GitHub Check: Test Python (4, 3.12)
  • GitHub Check: Test Python (2, 3.9)
  • GitHub Check: Test Python (5, 3.12)
  • GitHub Check: Test Python (1, 3.12)
  • GitHub Check: Test Python (5, 3.9)
  • GitHub Check: Test Python (3, 3.9)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

Copilot AI left a comment

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 implements type embedding compression for the se_atten descriptor to optimize inference performance. The implementation precomputes embedding network outputs for all type combinations and uses direct indexing during forward passes instead of computing embeddings on-the-fly.

Key changes:

  • Added type_embedding_compression() method to precompute type embeddings for all combinations (one-side: ntypes+1, two-side: (ntypes+1)²)
  • Refactored forward pass to use precomputed embeddings when available, with cleaner indexing operations
  • Integrated type embedding compression into the DPA1 descriptor's enable_compression() workflow

Reviewed Changes

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

File Description
deepmd/pt/model/descriptor/se_atten.py Added type embedding compression method with precomputation logic and updated forward pass to conditionally use precomputed embeddings with simplified indexing
deepmd/pt/model/descriptor/dpa1.py Integrated type embedding compression call into the existing compression enablement flow

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

@OutisLi
Copy link
Collaborator Author

OutisLi commented Nov 18, 2025

The speed comparison be shown below through the same simulation using LAMMPS to a 1000 atoms 3C-SiC system. This PR leads to roughly 20% speedup. Considering only 2 types of atoms in total, the improvement is quite obvious.

atten_v2 with no attention layer before compression:
no.log

after compression with no type embedding compression:
before.log

after compression with type embedding compression:
new.log

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
deepmd/pt/model/descriptor/se_atten.py (1)

455-499: LGTM! Validation checks address previous review feedback.

The implementation correctly precomputes type embeddings for all combinations:

  • One-side: (ntypes+1) neighbor embeddings
  • Two-side: (ntypes+1)² pair embeddings using index formula center_type * nt + neighbor_type

The use of .detach() is appropriate for cached precomputed values.

The static analysis TRY003 warnings at lines 468 and 470-472 are style suggestions about error message length. The current messages are clear and descriptive, so addressing this is optional. If you prefer to follow the style guide strictly, you could define custom exception classes.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d70a397 and 7f776fa.

📒 Files selected for processing (1)
  • deepmd/pt/model/descriptor/se_atten.py (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
deepmd/pt/model/descriptor/se_atten.py (1)
deepmd/pt/model/network/network.py (2)
  • TypeEmbedNet (268-358)
  • get_full_embedding (317-332)
🪛 Ruff (0.14.5)
deepmd/pt/model/descriptor/se_atten.py

468-468: Avoid specifying long messages outside the exception class

(TRY003)


470-472: Avoid specifying long messages outside the exception class

(TRY003)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (22)
  • GitHub Check: Test Python (4, 3.12)
  • GitHub Check: Test Python (1, 3.9)
  • GitHub Check: Test Python (5, 3.9)
  • GitHub Check: Test Python (3, 3.12)
  • GitHub Check: Test Python (1, 3.12)
  • GitHub Check: Test Python (2, 3.9)
  • GitHub Check: Test C++ (true)
  • GitHub Check: Build C library (2.14, >=2.5.0,<2.15, libdeepmd_c_cu11.tar.gz)
  • GitHub Check: Build C library (2.18, libdeepmd_c.tar.gz)
  • GitHub Check: Analyze (python)
  • GitHub Check: Analyze (c-cpp)
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build wheels for cp310-manylinux_aarch64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build wheels for cp311-macosx_x86_64
  • GitHub Check: Build wheels for cp311-win_amd64
  • GitHub Check: Build wheels for cp311-macosx_arm64
  • GitHub Check: Build C++ (cuda120, cuda)
  • GitHub Check: Build C++ (cuda, cuda)
  • GitHub Check: Build C++ (clang, clang)
  • GitHub Check: Build C++ (cpu, cpu)
  • GitHub Check: Build C++ (rocm, rocm)
🔇 Additional comments (3)
deepmd/pt/model/descriptor/se_atten.py (3)

30-32: LGTM!

The import is correctly added to support the type hint in the new type_embedding_compression method.


278-288: LGTM!

The attribute initialization and comments clearly separate geometric compression from type embedding compression concerns.


627-663: LGTM! Index formula correctly matches precomputation.

The forward path properly leverages cached embeddings when available and falls back to on-the-fly computation otherwise:

  • One-side (627-633): Directly indexes cached embeddings by neighbor type
  • Two-side (634-663): Uses index formula center_type * ntypes_with_padding + neighbor_type which matches the precomputation layout

The fallback logic ensures backward compatibility with non-compressed models.

@codecov
Copy link

codecov bot commented Nov 18, 2025

Codecov Report

❌ Patch coverage is 94.44444% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.26%. Comparing base (da452d7) to head (c35082d).
⚠️ Report is 5 commits behind head on devel.

Files with missing lines Patch % Lines
deepmd/pt/model/descriptor/se_atten.py 94.11% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #5057      +/-   ##
==========================================
+ Coverage   84.24%   84.26%   +0.02%     
==========================================
  Files         709      709              
  Lines       70236    70305      +69     
  Branches     3623     3619       -4     
==========================================
+ Hits        59169    59244      +75     
+ Misses       9900     9893       -7     
- Partials     1167     1168       +1     

☔ View full report in Codecov by Sentry.
📢 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.

…se_atten

- Added functionality to enable type embedding compression in the  class, specifically for two-side mode.
- Introduced a new method  to precompute type embedding network outputs for all type pair combinations, optimizing inference by using precomputed values.
- Updated the  method to utilize precomputed embeddings when compression is enabled, improving performance during inference.

This enhancement allows for more efficient handling of type embeddings in the descriptor model.
…andling in se_atten

- Streamlined the index calculation for neighbor types by removing unnecessary reshaping and expansion.
- Improved clarity in the handling of type embeddings, ensuring that the logic for two-side embeddings remains intact while enhancing readability.
- Maintained functionality for both compressed and uncompressed type embeddings, optimizing the inference process.

These changes contribute to cleaner code and maintain the performance benefits introduced in previous commits.
… se_atten

- Simplified the type embedding compression process by consolidating methods and removing unnecessary conditions.
- Enhanced clarity in the handling of one-side and two-side type embeddings, ensuring consistent functionality across both modes.
- Updated comments for better understanding of the compression logic and its implications on performance.

These changes contribute to cleaner code and improved maintainability of the descriptor model.
- Added runtime checks to ensure type embedding compression only operates in "strip" mode.
- Introduced validation for the initialization of `filter_layers_strip` to prevent runtime errors.
- Updated comments to clarify the expected dimensions of type embeddings, enhancing code readability.

These changes improve error handling and maintain the integrity of the type embedding compression logic.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
deepmd/pt/model/descriptor/se_atten.py (2)

639-663: Core logic is correct; consider improving shape comment consistency.

The index calculation correctly matches the precomputation formula, and the conditional logic properly uses cached embeddings when available.

However, the shape comments at lines 645, 650, and 655 use * as a dimension separator, which is inconsistent with standard Python tuple notation used elsewhere (e.g., line 642). Consider updating for clarity:

-                    # ((ntypes+1)^2) * (ntypes+1)^2 * nt
+                    # (ntypes+1, ntypes+1, nt)
                     type_embedding_nei = torch.tile(
                         type_embedding.view(1, ntypes_with_padding, nt),
                         [ntypes_with_padding, 1, 1],
                     )
-                    # (ntypes+1)^2 * ((ntypes+1)^2) * nt
+                    # (ntypes+1, ntypes+1, nt)
                     type_embedding_center = torch.tile(
                         type_embedding.view(ntypes_with_padding, 1, nt),
                         [1, ntypes_with_padding, 1],
                     )
-                    # ((ntypes+1)^2 * (ntypes+1)^2) * (nt+nt)
+                    # ((ntypes+1)^2, 2*nt)
                     two_side_type_embedding = torch.cat(
                         [type_embedding_nei, type_embedding_center], -1
                     ).reshape(-1, nt * 2)

467-472: Static analysis: Consider shorter exception messages (optional).

Ruff flags TRY003 warnings for the exception messages. While the current messages are clear and helpful, you could optionally shorten them or define custom exception classes if you want to follow strict style guidelines. Given the clarity of the current implementation, this is purely a nitpick.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7f776fa and 4f72994.

📒 Files selected for processing (2)
  • deepmd/pt/model/descriptor/dpa1.py (1 hunks)
  • deepmd/pt/model/descriptor/se_atten.py (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • deepmd/pt/model/descriptor/dpa1.py
🧰 Additional context used
🧬 Code graph analysis (1)
deepmd/pt/model/descriptor/se_atten.py (1)
deepmd/pt/model/network/network.py (2)
  • TypeEmbedNet (268-358)
  • get_full_embedding (317-332)
🪛 Ruff (0.14.5)
deepmd/pt/model/descriptor/se_atten.py

468-468: Avoid specifying long messages outside the exception class

(TRY003)


470-472: Avoid specifying long messages outside the exception class

(TRY003)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (29)
  • GitHub Check: Build C++ (cpu, cpu)
  • GitHub Check: Build C++ (cuda120, cuda)
  • GitHub Check: Build C++ (cuda, cuda)
  • GitHub Check: Build C++ (rocm, rocm)
  • GitHub Check: Build C++ (clang, clang)
  • GitHub Check: Build C library (2.14, >=2.5.0,<2.15, libdeepmd_c_cu11.tar.gz)
  • GitHub Check: Build C library (2.18, libdeepmd_c.tar.gz)
  • GitHub Check: Test C++ (true)
  • GitHub Check: Test C++ (false)
  • GitHub Check: Test Python (5, 3.9)
  • GitHub Check: Build wheels for cp311-macosx_x86_64
  • GitHub Check: Build wheels for cp311-win_amd64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build wheels for cp311-macosx_arm64
  • GitHub Check: Analyze (python)
  • GitHub Check: Build wheels for cp310-manylinux_aarch64
  • GitHub Check: Analyze (c-cpp)
  • GitHub Check: Test Python (6, 3.12)
  • GitHub Check: Test Python (4, 3.12)
  • GitHub Check: Test Python (6, 3.9)
  • GitHub Check: Test Python (5, 3.12)
  • GitHub Check: Test Python (3, 3.12)
  • GitHub Check: Test Python (4, 3.9)
  • GitHub Check: Test Python (1, 3.12)
  • GitHub Check: Test Python (2, 3.9)
  • GitHub Check: Test Python (1, 3.9)
  • GitHub Check: Test Python (2, 3.12)
  • GitHub Check: Test Python (3, 3.9)
🔇 Additional comments (4)
deepmd/pt/model/descriptor/se_atten.py (4)

30-32: LGTM!

The TypeEmbedNet import is necessary for the new type_embedding_compression method and is correctly placed.


278-288: LGTM!

Clear separation between geometric compression state and type embedding compression cache. The None initialization is appropriate for optional cached data.


467-472: Validation checks correctly implemented.

The validation checks match the requirements from past review comments, ensuring the method is only called in strip mode with initialized filter_layers_strip.


627-633: LGTM!

The conditional logic correctly uses cached embeddings when available and falls back to on-the-fly computation otherwise, ensuring backward compatibility.

- Replaced direct assignment of `type_embd_data` with a call to `register_buffer` for better memory management.
- Improved clarity by using a temporary variable `embd_tensor` for storing the output of the embedding network before registration.
- Maintained functionality for both one-side and two-side type embeddings, ensuring consistent behavior across modes.

These changes enhance the maintainability and performance of the descriptor model.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
deepmd/pt/model/descriptor/se_atten.py (1)

278-289: Critical bug confirmed: register_buffer will raise KeyError at runtime

PyTorch's register_buffer raises KeyError if an attribute with that name already exists on the Module and is not already a registered buffer. The current code at line 288 sets type_embd_data as a plain attribute, and then lines 483 and 499 attempt to register it as a buffer, which will fail with the error: KeyError("attribute 'type_embd_data' already exists").

The review's suggested fix is correct and idiomatic: register the buffer in __init__ and update it later via direct assignment, as this keeps the registered buffer object and its registration. Simply change line 288 to register the buffer with None initially, then assign the computed tensor directly in type_embedding_compression.

Apply the suggested diff to fix the immediate runtime error.

🧹 Nitpick comments (1)
deepmd/pt/model/descriptor/se_atten.py (1)

455-472: Strip‑mode type‑embedding compression logic looks consistent; only minor comment nits

Functionally, the new type_embedding_compression and its use in the strip‑mode forward path look sound:

  • One‑side case: precomputes filter_layers_strip.networks[0](full_embd) with shape (ntypes+1, ng) and reuses it via direct indexing in forward — matching the previous on‑the‑fly behavior.
  • Two‑side case: constructs (neighbor, center) pairs so that the flattened layout matches idx = center_type * ntypes_with_padding + neighbor_type used in forward; the reuse via tt_full[idx] is consistent with the original computation.
  • Forward’s if self.type_embd_data is not None branches correctly fall back to the old path when precomputation is disabled, so behavior is preserved when compression isn’t used.

The only issues here are cosmetic: a few shape comments around Lines 645‑656 are slightly misleading (e.g., repeated ((ntypes+1)^2) * ... text rather than clearly stating the 3‑D tensor shapes), but they don’t affect correctness. You may optionally clean those up for future readers.

Also applies to: 627-633, 640-643, 645-661, 663-663

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c42ffe5 and bffe486.

📒 Files selected for processing (1)
  • deepmd/pt/model/descriptor/se_atten.py (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
deepmd/pt/model/descriptor/se_atten.py (1)
deepmd/pt/model/network/network.py (3)
  • TypeEmbedNet (268-358)
  • Tensor (36-37)
  • get_full_embedding (317-332)
🪛 Ruff (0.14.5)
deepmd/pt/model/descriptor/se_atten.py

468-468: Avoid specifying long messages outside the exception class

(TRY003)


470-472: Avoid specifying long messages outside the exception class

(TRY003)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (29)
  • GitHub Check: Build C++ (clang, clang)
  • GitHub Check: Build C library (2.14, >=2.5.0,<2.15, libdeepmd_c_cu11.tar.gz)
  • GitHub Check: Build C library (2.18, libdeepmd_c.tar.gz)
  • GitHub Check: Build C++ (cpu, cpu)
  • GitHub Check: Build C++ (rocm, rocm)
  • GitHub Check: Build C++ (cuda120, cuda)
  • GitHub Check: Build C++ (cuda, cuda)
  • GitHub Check: Test Python (6, 3.9)
  • GitHub Check: Test Python (5, 3.12)
  • GitHub Check: Test Python (6, 3.12)
  • GitHub Check: Test Python (2, 3.12)
  • GitHub Check: Test Python (1, 3.12)
  • GitHub Check: Test Python (1, 3.9)
  • GitHub Check: Test Python (5, 3.9)
  • GitHub Check: Test Python (4, 3.12)
  • GitHub Check: Test Python (4, 3.9)
  • GitHub Check: Test Python (3, 3.12)
  • GitHub Check: Test Python (2, 3.9)
  • GitHub Check: Test Python (3, 3.9)
  • GitHub Check: Analyze (python)
  • GitHub Check: Analyze (c-cpp)
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build wheels for cp310-manylinux_aarch64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build wheels for cp311-macosx_arm64
  • GitHub Check: Build wheels for cp311-win_amd64
  • GitHub Check: Test C++ (true)
  • GitHub Check: Build wheels for cp311-macosx_x86_64
  • GitHub Check: Test C++ (false)
🔇 Additional comments (1)
deepmd/pt/model/descriptor/se_atten.py (1)

30-32: TypeEmbedNet import matches new compression API

Importing TypeEmbedNet from deepmd.pt.model.network.network aligns with the new type_embedding_compression signature and the provided implementation of TypeEmbedNet.get_full_embedding; no issues here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
deepmd/pt/model/descriptor/se_atten.py (2)

455-504: type_embedding_compression implementation is sound; consider minor robustness and style tweaks

The precomputation logic for both one-side and two-side cases, plus registering type_embd_data as a buffer, aligns with the forward-path indexing and fixes prior device-movement issues—looks correct overall.

Non-blocking refinements you might consider:

  • Add light shape checks on full_embd (e.g., nt == self.ntypes + 1 and t_dim == self.tebd_dim) to fail fast with clearer errors if a mismatched TypeEmbedNet is accidentally wired in.
  • Ruff’s TRY003 hints here: if you want to satisfy it, you could slightly shorten the RuntimeError messages or factor them into dedicated exception types/constants instead of long inline strings.

All of these are optional; behavior as written is fine.


631-667: Strip-mode forward reuse of cached embeddings is consistent; comment shapes could be clearer

The new checks on self.type_embd_data in both one-side and two-side strip paths correctly match the buffer layout from type_embedding_compression, and the index construction (center_type * ntypes_with_padding + neighbor_type) is consistent with the (ntypes+1)² table size.

For readability only, the shape comments in the two-side fallback (around lines 649–655) currently read like chained products (e.g. ((ntypes+1)^2) * (ntypes+1)^2 * nt); rewriting them in a more conventional tensor-shape style such as (ntypes_with_padding, ntypes_with_padding, nt) would make the intent clearer to future readers.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bffe486 and 83165db.

📒 Files selected for processing (1)
  • deepmd/pt/model/descriptor/se_atten.py (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
deepmd/pt/model/descriptor/se_atten.py (1)
deepmd/pt/model/network/network.py (3)
  • TypeEmbedNet (268-358)
  • Tensor (36-37)
  • get_full_embedding (317-332)
🪛 Ruff (0.14.5)
deepmd/pt/model/descriptor/se_atten.py

468-468: Avoid specifying long messages outside the exception class

(TRY003)


470-472: Avoid specifying long messages outside the exception class

(TRY003)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (28)
  • GitHub Check: Build wheels for cp311-win_amd64
  • GitHub Check: Build wheels for cp311-macosx_arm64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build wheels for cp310-manylinux_aarch64
  • GitHub Check: Build wheels for cp311-macosx_x86_64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Test Python (1, 3.12)
  • GitHub Check: Test Python (5, 3.12)
  • GitHub Check: Test Python (3, 3.12)
  • GitHub Check: Test Python (4, 3.12)
  • GitHub Check: Test Python (6, 3.12)
  • GitHub Check: Test Python (4, 3.9)
  • GitHub Check: Test Python (3, 3.9)
  • GitHub Check: Test Python (5, 3.9)
  • GitHub Check: Test Python (6, 3.9)
  • GitHub Check: Test Python (1, 3.9)
  • GitHub Check: Test Python (2, 3.12)
  • GitHub Check: Test Python (2, 3.9)
  • GitHub Check: Test C++ (true)
  • GitHub Check: Test C++ (false)
  • GitHub Check: Build C++ (cuda120, cuda)
  • GitHub Check: Build C++ (cpu, cpu)
  • GitHub Check: Build C++ (clang, clang)
  • GitHub Check: Build C++ (cuda, cuda)
  • GitHub Check: Build C++ (rocm, rocm)
  • GitHub Check: Analyze (c-cpp)
  • GitHub Check: Build C library (2.14, >=2.5.0,<2.15, libdeepmd_c_cu11.tar.gz)
  • GitHub Check: Build C library (2.18, libdeepmd_c.tar.gz)
🔇 Additional comments (2)
deepmd/pt/model/descriptor/se_atten.py (2)

30-32: TypeEmbedNet import usage is appropriate

Importing TypeEmbedNet here cleanly supports the type_embedding_compression signature without introducing unused or circular dependencies in the shown context. No issues.


278-288: Compression state separation looks good

Grouping compress_* and the new type_embd_data field together makes it clear which state belongs to geometric vs type-embedding compression, and the Optional[torch.Tensor] initialization aligns with the later buffer registration logic. Nothing blocking here.

Copy link
Collaborator

@iProzd iProzd left a comment

Choose a reason for hiding this comment

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

Could you add a simple ut for se_atten compression? See source/tests/pt/test_model_compression_se_a.py

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
source/tests/pt/test_model_compression_se_atten.py (1)

209-808: Consider adding consistent cleanup across test classes.

Only TestDeepPotAPBCExcludeTypes has a tearDownClass method. Consider adding cleanup to other test classes or adding a module-level tearDownModule function to remove all test artifacts consistently.

Example module-level cleanup:

def tearDownModule() -> None:
    # Clean up files created by _init_models
    _file_delete(INPUT)
    _file_delete(FROZEN_MODEL)
    _file_delete(COMPRESSED_MODEL)
    # Clean up files created by _init_models_skip_neighbor_stat
    _file_delete(FROZEN_MODEL_SKIP_NEIGHBOR_STAT)
    _file_delete(COMPRESSED_MODEL_SKIP_NEIGHBOR_STAT)
    # Clean up files created by _init_models_exclude_types
    _file_delete(INPUT_ET)
    _file_delete(FROZEN_MODEL_ET)
    _file_delete(COMPRESSED_MODEL_ET)
    # Clean up other artifacts
    _file_delete("out.json")
    _file_delete("compress.json")
    _file_delete("checkpoint")
    _file_delete("lcurve.out")
    _file_delete("model.ckpt")
    _file_delete("model-compression/checkpoint")
    _file_delete("model-compression")
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 83165db and 2d46027.

📒 Files selected for processing (1)
  • source/tests/pt/test_model_compression_se_atten.py (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-09-19T04:25:12.408Z
Learnt from: njzjz
Repo: deepmodeling/deepmd-kit PR: 4144
File: source/api_cc/tests/test_deeppot_dpa_pt.cc:166-246
Timestamp: 2024-09-19T04:25:12.408Z
Learning: Refactoring between test classes `TestInferDeepPotDpaPt` and `TestInferDeepPotDpaPtNopbc` is addressed in PR #3905.

Applied to files:

  • source/tests/pt/test_model_compression_se_atten.py
🧬 Code graph analysis (1)
source/tests/pt/test_model_compression_se_atten.py (1)
deepmd/calculator.py (1)
  • DP (36-159)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (29)
  • GitHub Check: Test C++ (false)
  • GitHub Check: Test C++ (true)
  • GitHub Check: Build C library (2.18, libdeepmd_c.tar.gz)
  • GitHub Check: Build C++ (clang, clang)
  • GitHub Check: Build C++ (cuda120, cuda)
  • GitHub Check: Build C++ (cpu, cpu)
  • GitHub Check: Build C library (2.14, >=2.5.0,<2.15, libdeepmd_c_cu11.tar.gz)
  • GitHub Check: Build C++ (cuda, cuda)
  • GitHub Check: Build C++ (rocm, rocm)
  • GitHub Check: Test Python (5, 3.9)
  • GitHub Check: Test Python (3, 3.9)
  • GitHub Check: Test Python (6, 3.9)
  • GitHub Check: Test Python (6, 3.12)
  • GitHub Check: Test Python (5, 3.12)
  • GitHub Check: Test Python (2, 3.9)
  • GitHub Check: Test Python (4, 3.9)
  • GitHub Check: Test Python (4, 3.12)
  • GitHub Check: Test Python (2, 3.12)
  • GitHub Check: Test Python (1, 3.12)
  • GitHub Check: Test Python (3, 3.12)
  • GitHub Check: Test Python (1, 3.9)
  • GitHub Check: Build wheels for cp311-win_amd64
  • GitHub Check: Build wheels for cp311-macosx_arm64
  • GitHub Check: Build wheels for cp310-manylinux_aarch64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build wheels for cp311-macosx_x86_64
  • GitHub Check: Analyze (python)
  • GitHub Check: Analyze (c-cpp)
🔇 Additional comments (6)
source/tests/pt/test_model_compression_se_atten.py (6)

1-25: LGTM!

The imports and precision setup follow standard patterns for deepmd-kit test files.


34-81: LGTM!

The model initialization correctly configures se_atten with compression-compatible settings and documents the critical attn_layer=0 requirement.


84-132: LGTM!

The exclude_types variant properly tests compression with type exclusion configured.


135-189: LGTM!

The skip-neighbor-stat variant correctly uses --skip-neighbor-stat during training and provides the input config during compression via -t flag.


192-207: LGTM!

Module-level setup appropriately initializes all model variants needed for the test suite.


810-811: LGTM!

Standard unittest main block.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
source/tests/pt/test_model_compression_se_atten.py (1)

27-31: Fix cleanup helper to handle non‑empty directories safely

os.rmdir only removes empty directories; in tearDownClass this helper is used on paths like "checkpoint" and "model-compression", which are expected to contain files. This can raise OSError and make tests fail during cleanup instead of during assertions.

Consider a more robust implementation:

-import os
+import os
+import shutil
@@
-def _file_delete(file) -> None:
-    if os.path.isdir(file):
-        os.rmdir(file)
-    elif os.path.isfile(file):
-        os.remove(file)
+def _file_delete(path: str) -> None:
+    if not os.path.exists(path):
+        return
+    if os.path.isdir(path):
+        shutil.rmtree(path, ignore_errors=True)
+    else:
+        try:
+            os.remove(path)
+        except OSError:
+            # Best-effort cleanup; don't fail tests just because deletion failed
+            pass
🧹 Nitpick comments (2)
source/tests/pt/test_model_compression_se_atten.py (2)

34-190: Consider factoring shared model‑init logic to reduce duplication

_init_models, _init_models_exclude_types, and _init_models_skip_neighbor_stat duplicate most of the descriptor and type_embedding setup and training/compression pipeline, differing only in a few keys and CLI flags. A small helper that accepts overrides (e.g., exclude_types and skip_neighbor_stat) would make future descriptor schema changes less error‑prone.


192-207: Optional: centralize cleanup for all generated models and artifacts

setUpModule creates multiple models (FROZEN_MODEL, COMPRESSED_MODEL, *_SKIP_NEIGHBOR_STAT, *_ET), but only TestDeepPotAPBCExcludeTypes.tearDownClass cleans up a subset of artifacts. Not strictly wrong, but you could:

  • Add a tearDownModule() that calls _file_delete on all generated models and common files, or
  • Extend the existing teardown to also cover the non‑ET variants,

to keep the test data directory clean across repeated runs and reduce potential crosstalk with other tests sharing tests_path.

Also applies to: 579-591

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2d46027 and 3606359.

📒 Files selected for processing (1)
  • source/tests/pt/test_model_compression_se_atten.py (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-09-19T04:25:12.408Z
Learnt from: njzjz
Repo: deepmodeling/deepmd-kit PR: 4144
File: source/api_cc/tests/test_deeppot_dpa_pt.cc:166-246
Timestamp: 2024-09-19T04:25:12.408Z
Learning: Refactoring between test classes `TestInferDeepPotDpaPt` and `TestInferDeepPotDpaPtNopbc` is addressed in PR #3905.

Applied to files:

  • source/tests/pt/test_model_compression_se_atten.py
🧬 Code graph analysis (1)
source/tests/pt/test_model_compression_se_atten.py (1)
deepmd/calculator.py (1)
  • DP (36-159)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (30)
  • GitHub Check: Test Python (6, 3.9)
  • GitHub Check: Test Python (6, 3.12)
  • GitHub Check: Test Python (4, 3.9)
  • GitHub Check: Test Python (4, 3.12)
  • GitHub Check: Test Python (5, 3.9)
  • GitHub Check: Test Python (3, 3.12)
  • GitHub Check: Test Python (5, 3.12)
  • GitHub Check: Test Python (3, 3.9)
  • GitHub Check: Test Python (2, 3.12)
  • GitHub Check: Test Python (2, 3.9)
  • GitHub Check: Test Python (1, 3.9)
  • GitHub Check: Test Python (1, 3.12)
  • GitHub Check: Analyze (c-cpp)
  • GitHub Check: Analyze (python)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Test C++ (false)
  • GitHub Check: Test C++ (true)
  • GitHub Check: Build C library (2.14, >=2.5.0,<2.15, libdeepmd_c_cu11.tar.gz)
  • GitHub Check: Build C library (2.18, libdeepmd_c.tar.gz)
  • GitHub Check: Build C++ (clang, clang)
  • GitHub Check: Build C++ (cpu, cpu)
  • GitHub Check: Build C++ (rocm, rocm)
  • GitHub Check: Build C++ (cuda120, cuda)
  • GitHub Check: Build C++ (cuda, cuda)
  • GitHub Check: Build wheels for cp311-win_amd64
  • GitHub Check: Build wheels for cp310-manylinux_aarch64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build wheels for cp311-macosx_x86_64
  • GitHub Check: Build wheels for cp311-macosx_arm64
🔇 Additional comments (1)
source/tests/pt/test_model_compression_se_atten.py (1)

519-546: Import verified — code change is correct

The from deepmd.calculator import DP import is valid and confirmed. The DP class is properly defined and exported in deepmd/calculator.py (line 33: __all__ = ["DP"]), and this import pattern is already used throughout the codebase in multiple PT tests and utilities (source/tests/infer/test_models.py, deepmd/pt/utils/ase_calc.py, etc.), confirming it's the standard approach for ASE/PT integration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
source/tests/pt/test_model_compression_se_atten.py (2)

520-547: Consider expanding ASE calculator test coverage.

The test_ase method validates the compressed model via the ASE interface, but it only exists in TestDeepPotALargeBoxNoPBC. Extending this test to other scenarios (PBC, exclude_types, skip-neighbor-stat) would strengthen verification that compression preserves correctness across all integration paths.


210-795: Optional: Consider reducing test code duplication.

The five test classes share significant boilerplate: identical coordinate arrays, atype lists, and near-identical test method implementations. Extracting common test logic to a base class or using parameterized tests (e.g., @pytest.mark.parametrize or unittest's subTest) could reduce maintenance burden and improve readability.

Example structure:

class BaseCompressionTest(unittest.TestCase):
    """Base class with shared test logic"""
    
    def _compare_eval(self, atomic=False, nframes=1):
        # Common comparison logic
        pass
    
    def test_1frame(self):
        self._compare_eval(atomic=False, nframes=1)

This is a nice-to-have improvement and can be deferred if test clarity is prioritized over DRY principles.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3606359 and cdd7272.

📒 Files selected for processing (1)
  • source/tests/pt/test_model_compression_se_atten.py (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-10-08T15:32:11.479Z
Learnt from: njzjz
Repo: deepmodeling/deepmd-kit PR: 4144
File: source/api_cc/tests/test_deeppot_dpa_pt.cc:166-246
Timestamp: 2024-10-08T15:32:11.479Z
Learning: Refactoring between test classes `TestInferDeepPotDpaPt` and `TestInferDeepPotDpaPtNopbc` is addressed in PR #3905.

Applied to files:

  • source/tests/pt/test_model_compression_se_atten.py
🧬 Code graph analysis (1)
source/tests/pt/test_model_compression_se_atten.py (1)
deepmd/calculator.py (1)
  • DP (36-159)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (29)
  • GitHub Check: Build C++ (clang, clang)
  • GitHub Check: Build C++ (rocm, rocm)
  • GitHub Check: Build C++ (cuda120, cuda)
  • GitHub Check: Build C++ (cuda, cuda)
  • GitHub Check: Build C++ (cpu, cpu)
  • GitHub Check: Test C++ (true)
  • GitHub Check: Test C++ (false)
  • GitHub Check: Test Python (3, 3.9)
  • GitHub Check: Build C library (2.18, libdeepmd_c.tar.gz)
  • GitHub Check: Build C library (2.14, >=2.5.0,<2.15, libdeepmd_c_cu11.tar.gz)
  • GitHub Check: Test Python (4, 3.9)
  • GitHub Check: Test Python (2, 3.9)
  • GitHub Check: Test Python (2, 3.12)
  • GitHub Check: Test Python (4, 3.12)
  • GitHub Check: Test Python (3, 3.12)
  • GitHub Check: Test Python (1, 3.12)
  • GitHub Check: Test Python (6, 3.12)
  • GitHub Check: Test Python (6, 3.9)
  • GitHub Check: Test Python (5, 3.12)
  • GitHub Check: Test Python (1, 3.9)
  • GitHub Check: Test Python (5, 3.9)
  • GitHub Check: Build wheels for cp311-win_amd64
  • GitHub Check: Build wheels for cp310-manylinux_aarch64
  • GitHub Check: Build wheels for cp311-macosx_x86_64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build wheels for cp311-macosx_arm64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Analyze (python)
  • GitHub Check: Analyze (c-cpp)
🔇 Additional comments (1)
source/tests/pt/test_model_compression_se_atten.py (1)

85-104: Inconsistent tebd_dim configuration across test scenarios.

The first model initialization (_init_models) explicitly sets "tebd_dim": 8 (line 49), but this configuration omits it, allowing the descriptor to use its default value. Since this PR introduces type embedding compression and tebd_dim controls the type embedding dimension, inconsistent values across test scenarios may lead to incomplete test coverage or unexpected behavior.

Please clarify whether omitting tebd_dim here is intentional (to test default behavior) or an oversight. If testing the default is not the goal, consider adding it for consistency:

     jdata["model"]["descriptor"] = {
         "type": "se_atten",
         "exclude_types": [[0, 1]],
         "sel": 120,
         "rcut_smth": 0.50,
         "rcut": 6.00,
         "neuron": [25, 50, 100],
+        "tebd_dim": 8,
         "axis_neuron": 16,
         "attn": 64,

The same concern applies to _init_models_skip_neighbor_stat (lines 130-148).

- Replaced the optional `type_embd_data` with a registered buffer to improve memory management.
- Adjusted conditional checks for type embedding usage to rely on the `compress` attribute, enhancing clarity and functionality.
- Removed the associated test file for model compression of se_atten, streamlining the test suite.

These changes enhance the maintainability and performance of the descriptor model while ensuring consistent behavior in type embedding compression.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
deepmd/pt/model/descriptor/se_atten.py (1)

469-474: Consider extracting error messages to reduce line length.

The validation logic is correct and addresses previous review concerns. However, the error messages are verbose. Consider defining them as constants or extracting to a separate line for better maintainability.

Based on static analysis hints.

Apply this diff:

     def type_embedding_compression(self, type_embedding_net: TypeEmbedNet) -> None:
         """Enable type embedding compression for strip mode.
 
         Precomputes embedding network outputs for all type combinations:
         - One-side: (ntypes+1) combinations (neighbor types only)
         - Two-side: (ntypes+1)² combinations (neighbor x center type pairs)
 
         Parameters
         ----------
         type_embedding_net : TypeEmbedNet
             The type embedding network that provides get_full_embedding() method
         """
+        strip_mode_error = "Type embedding compression only works in strip mode"
+        filter_init_error = (
+            "filter_layers_strip must be initialized for type embedding compression"
+        )
         if self.tebd_input_mode != "strip":
-            raise RuntimeError("Type embedding compression only works in strip mode")
+            raise RuntimeError(strip_mode_error)
         if self.filter_layers_strip is None:
-            raise RuntimeError(
-                "filter_layers_strip must be initialized for type embedding compression"
-            )
+            raise RuntimeError(filter_init_error)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cdd7272 and 01f30a5.

📒 Files selected for processing (1)
  • deepmd/pt/model/descriptor/se_atten.py (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
deepmd/pt/model/descriptor/se_atten.py (1)
deepmd/pt/model/network/network.py (2)
  • TypeEmbedNet (268-358)
  • get_full_embedding (317-332)
🪛 Ruff (0.14.5)
deepmd/pt/model/descriptor/se_atten.py

470-470: Avoid specifying long messages outside the exception class

(TRY003)


472-474: Avoid specifying long messages outside the exception class

(TRY003)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (29)
  • GitHub Check: Build C library (2.14, >=2.5.0,<2.15, libdeepmd_c_cu11.tar.gz)
  • GitHub Check: Build C library (2.18, libdeepmd_c.tar.gz)
  • GitHub Check: Build C++ (rocm, rocm)
  • GitHub Check: Build C++ (clang, clang)
  • GitHub Check: Build C++ (cuda, cuda)
  • GitHub Check: Build wheels for cp311-macosx_arm64
  • GitHub Check: Build C++ (cuda120, cuda)
  • GitHub Check: Build C++ (cpu, cpu)
  • GitHub Check: Build wheels for cp310-manylinux_aarch64
  • GitHub Check: Build wheels for cp311-macosx_x86_64
  • GitHub Check: Build wheels for cp311-win_amd64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Build wheels for cp311-manylinux_x86_64
  • GitHub Check: Analyze (python)
  • GitHub Check: Analyze (c-cpp)
  • GitHub Check: Test Python (3, 3.12)
  • GitHub Check: Test C++ (true)
  • GitHub Check: Test C++ (false)
  • GitHub Check: Test Python (6, 3.9)
  • GitHub Check: Test Python (4, 3.12)
  • GitHub Check: Test Python (4, 3.9)
  • GitHub Check: Test Python (5, 3.12)
  • GitHub Check: Test Python (2, 3.12)
  • GitHub Check: Test Python (6, 3.12)
  • GitHub Check: Test Python (5, 3.9)
  • GitHub Check: Test Python (1, 3.12)
  • GitHub Check: Test Python (3, 3.9)
  • GitHub Check: Test Python (2, 3.9)
  • GitHub Check: Test Python (1, 3.9)
🔇 Additional comments (4)
deepmd/pt/model/descriptor/se_atten.py (4)

30-32: LGTM!

The import of TypeEmbedNet is necessary for the new type embedding compression feature, specifically to access the get_full_embedding() method.


287-290: LGTM!

Using register_buffer() for type_embd_data ensures it automatically moves with the model during device transfers (e.g., .to('cuda')). This correctly addresses the device handling concern from previous reviews.


476-506: LGTM!

The precomputation logic is correct and efficient:

  • One-side path: Precomputes embeddings for all (ntypes+1) neighbor types
  • Two-side path: Precomputes embeddings for all (ntypes+1)² neighbor×center pairs using memory-efficient broadcasting

The indexing formula (idx = center_type * nt + neighbor_type on line 646) correctly matches the flattened 2D structure created here. Using torch.no_grad() and .detach() prevents gradient tracking for cached data.


633-669: LGTM!

The forward method correctly integrates the cached type embeddings:

  • One-side path (633-639): Uses cached type_embd_data when compression is enabled, otherwise computes on-the-fly
  • Two-side path (641-669): Uses cached data indexed by center_type * nt + neighbor_type, with fallback that correctly replicates the precomputation structure

The branching logic preserves existing behavior when compression is disabled while enabling the performance optimization when enabled.

@OutisLi
Copy link
Collaborator Author

OutisLi commented Nov 22, 2025

Could you add a simple ut for se_atten compression? See source/tests/pt/test_model_compression_se_a.py

This can be merged first, I will commit another request later. I am having some trouble with the test.

@OutisLi OutisLi requested a review from iProzd November 23, 2025 07:22
@iProzd iProzd added this pull request to the merge queue Nov 24, 2025
Merged via the queue into deepmodeling:devel with commit 86cb76f Nov 24, 2025
60 checks passed
@OutisLi OutisLi deleted the pr/atten_compress branch November 25, 2025 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants