Make BackendModelFactory class injection complete and required (no silent dpmodel fallback)
Maintainer thường phản hồi trong vòng 3 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Tái cấu trúc
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python, pytorch, tensorflow
- Lĩnh vực
- backend, machine-learning
Hướng nghiên cứu
Đọc deepmd/dpmodel/model/model_factory.py và so sánh bốn điểm khởi tạo trong deepmd/dpmodel/model/model.py, deepmd/jax/model/model.py, deepmd/tf2/model/model.py và deepmd/pt_expt/model/get_model.py. Xem lại ngữ cảnh của #5960 và #5964, sau đó chọn và cố định quyết định về InnerPotentialAtomicModel bằng một test. Hoàn thành nghĩa là mọi injection đều bắt buộc, không còn đường dẫn khởi tạo fallback nào và các class bị thiếu sẽ thất bại với TypeError.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
BackendModelFactory (deepmd/dpmodel/model/model_factory.py, introduced in #5964) constructs backend model objects from injected backend classes. The injection list is incomplete and partially optional, which allows a wrapping backend to silently fall back to constructing dpmodel-class objects. This is the root cause of the use_amp loss fixed in #5960 and should be closed off structurally.
Problem
Current BackendModelFactory.__init__:
- required:
descriptor_base,fitting_base,model_base,backend_name - optional (default
None→ dpmodel class):atomic_model,pairtab_model,zbl_model,linear_atomic_model - not injectable at all (hardcoded import inside the factory body):
InnerPotentialAtomicModel
For a backend that wraps dpmodel classes (pt_expt), an omitted injection is not an error: the factory builds a dpmodel-class composition, and the backend's model wrapper later converts it via deserialize(serialize()). That conversion keeps only the portable record, so any runtime state the live children hold is silently dropped. This is exactly how #5960's bug happened: the factory hardcoded the dpmodel LinearEnergyAtomicModel, and a configured use_amp: false was lost during pt_expt assembly — numerically invisible to every cross-backend parity test, because the loss changes precision policy, not the math.
A half-injected factory is worse than no sharing: it looks canonical while constructing wrong-backend objects, and the failure mode is silent degradation instead of an error.
Proposal
- Make all class-injection parameters required (no
Nonedefault, no fallback import inside the factory):atomic_model,pairtab_model,zbl_model— already passed explicitly by all four instantiation sites (deepmd/dpmodel/model/model.py,deepmd/jax/model/model.py,deepmd/tf2/model/model.py,deepmd/pt_expt/model/get_model.py), so this is zero-cost.linear_atomic_model— currently passed only by pt_expt. dpmodel/jax/tf2 must state their choice explicitly (for them the dpmodel class is correct — the point is that "I use the native class" becomes a visible, reviewed decision instead of a silent default).
- Remove the fallback imports (
LinearEnergyAtomicModel as LinearEnergyAtomicModelDP,linear_atomic_model or ...) from the factory body. - Open question —
InnerPotentialAtomicModel: it is constructed inside the factory (model_factory.py:325) from a hardcoded import. Today this is harmless because the model is purely analytical (no trainable arrays, no runtime state), so the wrapping backend's conversion is lossless (verified in #5960, where an unusedinner_potential_modelparameter was removed for exactly that reason). But "the conversion happens to be lossless today" was also the implicit assumption for the linear class before #5960. Either:- (a) inject it like the others, for uniformity; or
- (b) keep it hardcoded and pin the exemption with a comment + a negative test asserting the class carries no non-portable state.
Acceptance
BackendModelFactory(...)with a missing class raisesTypeErrorat import time of the backend module — a missed injection is a hard failure, not a silent fallback.- No dpmodel-class fallback import remains inside any factory construction path (grep-clean for the
or LinearEnergyAtomicModelDPpattern). - The
InnerPotentialAtomicModeldecision (3a or 3b) is implemented and pinned by a test.
References
- #5964 — introduced the shared factory / canonical
linear_enercomposition. - #5960 — the
use_ampsilent-loss bug caused by the hardcoded linear class; fixed by injectinglinear_atomic_model(pt_expt only).
- Ngôn ngữ chính
- Python
- Star
- 2.1k
- Fork
- 663
- Merge trung bình
- 3 ngày 11 giờ
- Pull request đã merge (30 ngày)
- 25
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của deepmodeling/deepmd-kit
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
deepmodeling/deepmd-kit#6086 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Fine-tune descriptor mismatch warning should ignore seedCó thể đã có người làm @SiyuanChenToDo đã nhận 23 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
deepmodeling/deepmd-kit#6038 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Docs enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
deepmodeling/deepmd-kit#5766 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
branch: master lang: py todo comment type: todo
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
deepmodeling/deepmd-kit#5480 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
branch: master lang: toml todo comment type: todo
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
deepmodeling/deepmd-kit#5462 ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của deepmodeling/deepmd-kit
Issue tương tự
-
needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
gke-labs/kube-agents#5671 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
docs(auth): Method B step 4 should tell users to tick "Use this client for an AI-powered agent"Đang mởdocumentation next-release v0.9.6
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
khuisman/mcp-gee-sweet#1446 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
In-box secret files written before their chmod: lc-creds, stacks tee, and the workspace tokenĐang mởmodel:sonnet runtime:claude security size:S
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
FootprintAI/Containarium#3671 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
HolidayBase: reassigning `language` does not re-initialize translations or re-populate holidaysCó thể đã có người làm @shikhabhadoria đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
vacanza/holidays#4116 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug CLI exec
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày