[PyTorch] Guard/document single parameter feature for grouped linear#2955
[PyTorch] Guard/document single parameter feature for grouped linear#2955ksivaman wants to merge 2 commits intoNVIDIA:mainfrom
Conversation
Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
|
/te-ci pytorch L0 |
Greptile SummaryThis PR guards the experimental Confidence Score: 4/5Safe to merge — changes are limited to documentation, an env-var guard, and a shared utility; no logic regressions identified. Only P2 (style) findings present; the implementation is correct and consistent with existing patterns in the codebase. transformer_engine/pytorch/utils.py — env var parsing without error handling on line 93. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["User constructs GroupedLinear\n(single_grouped_weight=True\nor single_grouped_bias=True)"] --> B["resolve_grouped_linear_single_param_flags()"]
B --> C{Either flag true?}
C -- No --> D["Return flags unchanged (no-op)"]
C -- Yes --> E{NVTE_GROUPED_LINEAR_SINGLE_PARAM set?}
E -- No --> F["Emit UserWarning: env var not set, feature disabled"]
F --> G["Return False, False (fall back to per-expert params)"]
E -- Yes --> H["Emit UserWarning: experimental / non-deterministic"]
H --> I["Return original flags (feature enabled)"]
Reviews (1): Last reviewed commit: "Merge branch 'main' into single_param_be..." | Re-trigger Greptile |
| if not (single_grouped_weight or single_grouped_bias): | ||
| return single_grouped_weight, single_grouped_bias | ||
|
|
||
| env_enabled = int(os.environ.get("NVTE_GROUPED_LINEAR_SINGLE_PARAM", "0")) > 0 |
There was a problem hiding this comment.
Non-integer env var value will raise
ValueError
int(os.environ.get("NVTE_GROUPED_LINEAR_SINGLE_PARAM", "0")) will throw an uncaught ValueError if the variable is set to a non-numeric string (e.g. "true", "yes"). Wrapping in a try/except would give a cleaner error message. This is consistent with other similar env-var checks in the file, so this is a pre-existing pattern rather than a new regression — flagging for awareness.
| env_enabled = int(os.environ.get("NVTE_GROUPED_LINEAR_SINGLE_PARAM", "0")) > 0 | |
| try: | |
| env_enabled = int(os.environ.get("NVTE_GROUPED_LINEAR_SINGLE_PARAM", "0")) > 0 | |
| except ValueError: | |
| env_enabled = False |
timmoon10
left a comment
There was a problem hiding this comment.
This logic breaks backward compatibility since we can no longer rely on the module kwargs to configure single grouped params. I guess we've already been treating single grouped params as an experimental feature. We should keep this instability in mind whenever we use this feature externally, e.g. in Mcore.
| single_grouped_weight: bool, | ||
| single_grouped_bias: bool, |
There was a problem hiding this comment.
While we are breaking backward compatibility, we might consider consolidating these options together. Do we really want to take on the burden of supporting the case with a single grouped weight and discrete bias, or discrete weights and single grouped bias?
| if not (single_grouped_weight or single_grouped_bias): | ||
| return single_grouped_weight, single_grouped_bias | ||
|
|
||
| env_enabled = int(os.environ.get("NVTE_GROUPED_LINEAR_SINGLE_PARAM", "0")) > 0 |
There was a problem hiding this comment.
If we only respect the kwargs if an envvar is set, it doesn't really make sense to keep the envvars rather than just checking the envvar. I guess we're half-heartedly maintaining/preparing the stable API for this feature.
Description
Guard/document single parameter feature for grouped linear.
Type of change
Changes
Checklist: