Repository navigation
Conversation
|
Went over this again while it sits at the gate, and checked current main too. The same delegation pattern is in mistral.py, so I'm flagging it here instead of adding it to this PR.
None of the test jobs here have run: only lint, check-changes and the label/pr-body helpers got through, everything else is blocked by pr-gate (Missing required label 'run-ci'), so nothing has been exercised by CI yet. Rebased onto current master, and it continues cjhgo's #7281, which got two approvals back in 2025 and then went idle after a lint request; that one is superseded by this. @mickqian could you add the run-ci label when you get a chance? It's +20/-7 in one file and lint is green. |
|
@Fridge003, could you review this MiniCPMV fix when you have a chance, or advise me on the right next step? The required test jobs are still blocked because the |
MiniCPMV delegates every undefined attribute to the inner self.minicpmv module, so methods like eval()/train()/to()/cuda() returned the inner module instead of the wrapper, breaking method chaining. Wrap delegated callables so a result identical to self.minicpmv is rewritten to self, and raise AttributeError for the 'minicpmv' name instead of returning None so hasattr()/getattr() behave correctly before __init__ assigns it. Drop the redundant eval() override on MiniCPMV4_5: nn.Module.eval() already returns self, and the wrapper now rewrites it anyway. Continues the work from cjhgo's sgl-project#7281, rebased and extended to current master.
c385b4e to
54a9c93
Compare
Motivation
MiniCPMVdelegates every undefined attribute to the innerself.minicpmvmodule, somodel.eval()/train()/to()/cuda()returned the inner module instead of the wrapper — breaking method chaining. Concretely,loader.pyhas ~16 sites returningmodel.eval(); for MiniCPM-V 2.6/4.0/4.5 the returned object is the innerMiniCPMBaseModel, which lacks theload_weightsdefined on the wrapper — so the RL weight-update path (weight_updater.py→get_model().load_weights(...)) receives a module without that method.Continues the work from cjhgo's #7281, rebased and extended onto current master.
Modifications
__getattr__("minicpmv")now raisesAttributeErrorinstead of returningNone— the old code madehasattr(obj, "minicpmv")wrongly returnTruebefore__init__assigned it (and returningNonewould mask infinite recursion if the guard were ever reordered).is self.minicpmv, it is rewritten toself. The guardnot isinstance(attr, nn.Module)keeps submodule attributes likemodel.llm/model.vpmpassing through as real modules — nn.Module is callable, so without the guard they would be wrapped into closures.functools.wrapskeeps__name__andinspect.signatureintact on wrapped methods.eval()override inMiniCPMV4_5is removed — it was a semantic no-op (nn.Module.eval()already returnsself), and the general wrapper now covers chaining for all versions includingMiniCPMV4_6ForConditionalGeneration.Testing
Extracted the real
__getattr__/__call__source from the modified file viaast(the module can't be imported without the full sglang runtime) and grafted it onto a stub wrapping a realtorch.nn.Module, 27 checks covering:eval()/train()/to()/float()/half()/cuda()all return the wrapper and mutate the inner module;train(mode)propagates the flag;eval().train().eval()chains;load_state_dictreturns_IncompatibleKeysuntouched; submodule attributes (model.llm) stay real modules with working.weight; non-callable attributes pass through by identity;hasattr(w, "minicpmv")is False before init and True after;__call__forwards to the inner module.Known pre-existing quirks (unchanged by this PR):
setattron the wrapper writes to the wrapper's__dict__rather than delegating to the inner module, and Python <3.11 pickle edge cases — both behave identically on master.First-time contributor note: CI needs a maintainer to apply the
run-cilabel.CI States
Latest PR Test (Base): ❌ Run #39474630317
Latest PR Test (Extra): ❌ Run #39474630519
Latest PR Test (AMD ROCm 10): ❌ Run #39474630268