Skip to content

fix: separate model weights from inputs in extraction output#712

Closed
xjtu-L wants to merge 1 commit into
PaddlePaddle:developfrom
xjtu-L:fix/separator-weights-from-inputs
Closed

fix: separate model weights from inputs in extraction output#712
xjtu-L wants to merge 1 commit into
PaddlePaddle:developfrom
xjtu-L:fix/separator-weights-from-inputs

Conversation

@xjtu-L
Copy link
Copy Markdown

@xjtu-L xjtu-L commented May 18, 2026

Summary

  • Fix extractor.py to correctly separate model parameters/buffers from placeholder inputs (including SymInt symbols like s0, s1) when saving tensor metadata
  • Previously, all placeholder params were passed to convert_state_and_inputs(params, []), causing SymInt placeholders to appear in weight_meta.py as Program_weight_tensor_meta_s0
  • Now uses object identity (id()) to distinguish original model params/buffers from real inputs, writing weights to weight_meta.py and inputs to input_meta.py
  • Updates utils.py to handle dict-style example_inputs with named tensor infos

Background

When torch.compile with FX tracing lifts model parameters and buffers into placeholder nodes, the extractor treated them identically to real model inputs. This caused:

  1. SymInt symbols (s0, s1, etc.) to be written to weight_meta.py as fake weights
  2. Model parameters and buffers to be written to input_meta.py instead of weight_meta.py
  3. Downstream dimension generalization (_get_tensor_metas) to merge both files, propagating the redundant entries

Changes

graph_net/torch/extractor.py

  • GraphExtractor.__init__: add param_buffer_ids parameter
  • wrapper(): collect id() of original model's named_parameters() and named_buffers(), pass to GraphExtractor
  • __call__(): split params into weights (by id match) and example_inputs, call convert_state_and_inputs(weights, example_inputs)

graph_net/torch/utils.py

  • convert_state_and_inputs_impl: support example_inputs as dict (named inputs)
  • save_converted_to_text: handle dict-of-tensor-infos for input_info, preserving placeholder names

Test Plan

  • No-param model: weight_meta.py empty, all inputs in input_meta.py
  • Nested modules: parameters correctly in weight_meta.py
  • Multi-input + buffer model: parameters and buffers in weight_meta.py, real inputs in input_meta.py
  • Parameter-only model (no buffer): correct split
  • ParameterList model: all list params in weight_meta.py
  • s0/s1 SymInt symbols never appear in weight_meta.py

@paddle-bot
Copy link
Copy Markdown

paddle-bot Bot commented May 18, 2026

Thanks for your contribution!

@paddle-bot paddle-bot Bot added the contributor External developers label May 18, 2026
@xjtu-L xjtu-L force-pushed the fix/separator-weights-from-inputs branch 3 times, most recently from 4ba97fe to 5545875 Compare May 20, 2026 09:56
Previously, `extractor.py` passed all placeholder params (including
lifted parameters, buffers, SymInt symbols, and real inputs) to
`convert_state_and_inputs(params, [])`, causing all of them to be
written to `weight_meta.py`. This led to SymInt placeholders like
`Program_weight_tensor_meta_s0` appearing in `weight_meta.py`, which
are not real model weights.

This change:
- Collects `id()` of original model parameters and buffers in `wrapper()`
- Passes them to `GraphExtractor` via `param_buffer_ids`
- Splits `params` into `weights` (params/buffers by identity) and
  `example_inputs` (real inputs including SymInt)
- Writes weights to `weight_meta.py` and inputs to `input_meta.py`
- Updates `utils.py` to handle dict-style `example_inputs`
@xjtu-L xjtu-L force-pushed the fix/separator-weights-from-inputs branch from 5545875 to bb404cb Compare May 20, 2026 11:09
@xjtu-L xjtu-L closed this May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant