Repository navigation
feat: Add configurable DTensor load precision - #2622
Open
Mingyu-Yang-1 wants to merge 6 commits into
Open
Mingyu-Yang-1 wants to merge 6 commits into
Mingyu-Yang-1 wants to merge 6 commits into
Conversation
RayenTian
reviewed
May 29, 2026
RayenTian
reviewed
May 29, 2026
Contributor
|
Thanks for the contribution, @Mingyu-Yang-1! Being able to load reference/teacher workers in lower precision is a nice memory win. A few comments above before this is ready to merge. |
Contributor
|
Would you please add some unit tests for this feature? |
Mingyu-Yang-1
pushed a commit
to Mingyu-Yang-1/NemoRL-Xtoken
that referenced
this pull request
May 31, 2026
Per review on NVIDIA-NeMo#2622: load_precision is only safe for reference/teacher workers. Loading trainable workers in bf16/fp16 silently degrades training by destroying master-weight precision. Thread init_optimizer through validate_and_prepare_config and raise ValueError when init_optimizer=True with non-float32 load_precision. Default remains float32 so existing trainable-worker configs are unaffected. Reference-worker configs (init_optimizer=False, used in distillation teacher and reward-model eval) can still opt into bf16 to save init-time memory. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Mingyu-Yang-1
pushed a commit
to Mingyu-Yang-1/NemoRL-Xtoken
that referenced
this pull request
May 31, 2026
Per review on NVIDIA-NeMo#2622: - DTensorConfig.load_precision: add inline doc explaining purpose (load-time dtype for from_pretrained), valid values (float32/bfloat16/float16), default (float32), and the trainable-worker float32 constraint enforced in validate_and_prepare_config. - examples/configs/distillation_math.yaml: add load_precision: bfloat16 to the teacher block to demonstrate the feature on the canonical distillation exemplar. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Contributor
|
/ok to test 52d8f45 |
Mingyu-Yang-1
pushed a commit
to Mingyu-Yang-1/NemoRL-Xtoken
that referenced
this pull request
Jun 2, 2026
Per review on NVIDIA-NeMo#2622: load_precision is only safe for reference/teacher workers. Loading trainable workers in bf16/fp16 silently degrades training by destroying master-weight precision. Thread init_optimizer through validate_and_prepare_config and raise ValueError when init_optimizer=True with non-float32 load_precision. Default remains float32 so existing trainable-worker configs are unaffected. Reference-worker configs (init_optimizer=False, used in distillation teacher and reward-model eval) can still opt into bf16 to save init-time memory. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> Signed-off-by: Mingyu Yang <[email protected]>
Mingyu-Yang-1
pushed a commit
to Mingyu-Yang-1/NemoRL-Xtoken
that referenced
this pull request
Jun 2, 2026
Per review on NVIDIA-NeMo#2622: - DTensorConfig.load_precision: add inline doc explaining purpose (load-time dtype for from_pretrained), valid values (float32/bfloat16/float16), default (float32), and the trainable-worker float32 constraint enforced in validate_and_prepare_config. - examples/configs/distillation_math.yaml: add load_precision: bfloat16 to the teacher block to demonstrate the feature on the canonical distillation exemplar. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> Signed-off-by: Mingyu Yang <[email protected]>
Mingyu-Yang-1
force-pushed
the
mingyyang/precision-control
branch
from
June 2, 2026 23:25
52d8f45 to
d41a3ec
Compare
Mingyu-Yang-1
added a commit
to Mingyu-Yang-1/NemoRL-Xtoken
that referenced
this pull request
Jun 2, 2026
Per review on NVIDIA-NeMo#2622, six tests added to TestValidateAndPrepareConfig covering the three requested categories: _precision_to_dtype helper: - test_precision_to_dtype_supported: float32/bfloat16/float16 map to the right torch.dtype - test_precision_to_dtype_invalid: unknown name raises ValueError load_precision validation in validate_and_prepare_config: - test_load_precision_default_is_float32: unset -> model_load_dtype=float32 - test_load_precision_bfloat16_reference_passes: init_optimizer=False + bf16 passes and sets model_load_dtype - test_load_precision_bfloat16_trainable_raises: init_optimizer=True + bf16 raises ValueError Consumer side (AutoConfig.from_pretrained): - test_load_precision_passed_to_autoconfig_from_pretrained: torch_dtype kwarg receives the configured model_load_dtype. Tests follow the test_precision_types / test_precision_validation_invalid patterns the reviewer flagged as templates. Signed-off-by: Mingyu Yang <[email protected]>
Signed-off-by: Mingyu Yang <[email protected]>
Per review on NVIDIA-NeMo#2622: load_precision is only safe for reference/teacher workers. Loading trainable workers in bf16/fp16 silently degrades training by destroying master-weight precision. Thread init_optimizer through validate_and_prepare_config and raise ValueError when init_optimizer=True with non-float32 load_precision. Default remains float32 so existing trainable-worker configs are unaffected. Reference-worker configs (init_optimizer=False, used in distillation teacher and reward-model eval) can still opt into bf16 to save init-time memory. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> Signed-off-by: Mingyu Yang <[email protected]>
Per review on NVIDIA-NeMo#2622: - DTensorConfig.load_precision: add inline doc explaining purpose (load-time dtype for from_pretrained), valid values (float32/bfloat16/float16), default (float32), and the trainable-worker float32 constraint enforced in validate_and_prepare_config. - examples/configs/distillation_math.yaml: add load_precision: bfloat16 to the teacher block to demonstrate the feature on the canonical distillation exemplar. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> Signed-off-by: Mingyu Yang <[email protected]>
Signed-off-by: Mingyu Yang <[email protected]>
Signed-off-by: Mingyu Yang <[email protected]>
Per review on NVIDIA-NeMo#2622, six tests added to TestValidateAndPrepareConfig covering the three requested categories: _precision_to_dtype helper: - test_precision_to_dtype_supported: float32/bfloat16/float16 map to the right torch.dtype - test_precision_to_dtype_invalid: unknown name raises ValueError load_precision validation in validate_and_prepare_config: - test_load_precision_default_is_float32: unset -> model_load_dtype=float32 - test_load_precision_bfloat16_reference_passes: init_optimizer=False + bf16 passes and sets model_load_dtype - test_load_precision_bfloat16_trainable_raises: init_optimizer=True + bf16 raises ValueError Consumer side (AutoConfig.from_pretrained): - test_load_precision_passed_to_autoconfig_from_pretrained: torch_dtype kwarg receives the configured model_load_dtype. Tests follow the test_precision_types / test_precision_validation_invalid patterns the reviewer flagged as templates. Signed-off-by: Mingyu Yang <[email protected]>
Mingyu-Yang-1
force-pushed
the
mingyyang/precision-control
branch
from
June 2, 2026 23:58
2b19718 to
88e33c4
Compare
Contributor
|
/ok to test 88e33c4 |
Contributor
|
@Mingyu-Yang-1 Thanks for the contribution! Overall look good to me. Triggered CI test. |
Contributor
|
@Mingyu-Yang-1 Seems there still are CI fails. Would you please fix them? |
avenkateshha
pushed a commit
that referenced
this pull request
Aug 6, 2026
Per review on #2622: load_precision is only safe for reference/teacher workers. Loading trainable workers in bf16/fp16 silently degrades training by destroying master-weight precision. Thread init_optimizer through validate_and_prepare_config and raise ValueError when init_optimizer=True with non-float32 load_precision. Default remains float32 so existing trainable-worker configs are unaffected. Reference-worker configs (init_optimizer=False, used in distillation teacher and reward-model eval) can still opt into bf16 to save init-time memory. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> Signed-off-by: Mingyu Yang <[email protected]>
avenkateshha
pushed a commit
that referenced
this pull request
Aug 6, 2026
Per review on #2622: - DTensorConfig.load_precision: add inline doc explaining purpose (load-time dtype for from_pretrained), valid values (float32/bfloat16/float16), default (float32), and the trainable-worker float32 constraint enforced in validate_and_prepare_config. - examples/configs/distillation_math.yaml: add load_precision: bfloat16 to the teacher block to demonstrate the feature on the canonical distillation exemplar. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> Signed-off-by: Mingyu Yang <[email protected]>
avenkateshha
pushed a commit
that referenced
this pull request
Aug 6, 2026
Per review on #2622, six tests added to TestValidateAndPrepareConfig covering the three requested categories: _precision_to_dtype helper: - test_precision_to_dtype_supported: float32/bfloat16/float16 map to the right torch.dtype - test_precision_to_dtype_invalid: unknown name raises ValueError load_precision validation in validate_and_prepare_config: - test_load_precision_default_is_float32: unset -> model_load_dtype=float32 - test_load_precision_bfloat16_reference_passes: init_optimizer=False + bf16 passes and sets model_load_dtype - test_load_precision_bfloat16_trainable_raises: init_optimizer=True + bf16 raises ValueError Consumer side (AutoConfig.from_pretrained): - test_load_precision_passed_to_autoconfig_from_pretrained: torch_dtype kwarg receives the configured model_load_dtype. Tests follow the test_precision_types / test_precision_validation_invalid patterns the reviewer flagged as templates. Signed-off-by: Mingyu Yang <[email protected]>
avenkateshha
pushed a commit
to avenkateshha/RL
that referenced
this pull request
Sep 17, 2026
Per review on NVIDIA-NeMo#2622: load_precision is only safe for reference/teacher workers. Loading trainable workers in bf16/fp16 silently degrades training by destroying master-weight precision. Thread init_optimizer through validate_and_prepare_config and raise ValueError when init_optimizer=True with non-float32 load_precision. Default remains float32 so existing trainable-worker configs are unaffected. Reference-worker configs (init_optimizer=False, used in distillation teacher and reward-model eval) can still opt into bf16 to save init-time memory. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> Signed-off-by: Mingyu Yang <[email protected]>
avenkateshha
pushed a commit
to avenkateshha/RL
that referenced
this pull request
Sep 17, 2026
Per review on NVIDIA-NeMo#2622: - DTensorConfig.load_precision: add inline doc explaining purpose (load-time dtype for from_pretrained), valid values (float32/bfloat16/float16), default (float32), and the trainable-worker float32 constraint enforced in validate_and_prepare_config. - examples/configs/distillation_math.yaml: add load_precision: bfloat16 to the teacher block to demonstrate the feature on the canonical distillation exemplar. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> Signed-off-by: Mingyu Yang <[email protected]>
avenkateshha
pushed a commit
to avenkateshha/RL
that referenced
this pull request
Sep 17, 2026
Per review on NVIDIA-NeMo#2622, six tests added to TestValidateAndPrepareConfig covering the three requested categories: _precision_to_dtype helper: - test_precision_to_dtype_supported: float32/bfloat16/float16 map to the right torch.dtype - test_precision_to_dtype_invalid: unknown name raises ValueError load_precision validation in validate_and_prepare_config: - test_load_precision_default_is_float32: unset -> model_load_dtype=float32 - test_load_precision_bfloat16_reference_passes: init_optimizer=False + bf16 passes and sets model_load_dtype - test_load_precision_bfloat16_trainable_raises: init_optimizer=True + bf16 raises ValueError Consumer side (AutoConfig.from_pretrained): - test_load_precision_passed_to_autoconfig_from_pretrained: torch_dtype kwarg receives the configured model_load_dtype. Tests follow the test_precision_types / test_precision_validation_invalid patterns the reviewer flagged as templates. Signed-off-by: Mingyu Yang <[email protected]>
2 of 4 tasks
avenkateshha
pushed a commit
to avenkateshha/RL
that referenced
this pull request
Sep 17, 2026
Per review on NVIDIA-NeMo#2622: load_precision is only safe for reference/teacher workers. Loading trainable workers in bf16/fp16 silently degrades training by destroying master-weight precision. Thread init_optimizer through validate_and_prepare_config and raise ValueError when init_optimizer=True with non-float32 load_precision. Default remains float32 so existing trainable-worker configs are unaffected. Reference-worker configs (init_optimizer=False, used in distillation teacher and reward-model eval) can still opt into bf16 to save init-time memory. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> Signed-off-by: Mingyu Yang <[email protected]>
avenkateshha
pushed a commit
to avenkateshha/RL
that referenced
this pull request
Sep 17, 2026
Per review on NVIDIA-NeMo#2622: - DTensorConfig.load_precision: add inline doc explaining purpose (load-time dtype for from_pretrained), valid values (float32/bfloat16/float16), default (float32), and the trainable-worker float32 constraint enforced in validate_and_prepare_config. - examples/configs/distillation_math.yaml: add load_precision: bfloat16 to the teacher block to demonstrate the feature on the canonical distillation exemplar. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> Signed-off-by: Mingyu Yang <[email protected]>
avenkateshha
pushed a commit
to avenkateshha/RL
that referenced
this pull request
Sep 17, 2026
Per review on NVIDIA-NeMo#2622, six tests added to TestValidateAndPrepareConfig covering the three requested categories: _precision_to_dtype helper: - test_precision_to_dtype_supported: float32/bfloat16/float16 map to the right torch.dtype - test_precision_to_dtype_invalid: unknown name raises ValueError load_precision validation in validate_and_prepare_config: - test_load_precision_default_is_float32: unset -> model_load_dtype=float32 - test_load_precision_bfloat16_reference_passes: init_optimizer=False + bf16 passes and sets model_load_dtype - test_load_precision_bfloat16_trainable_raises: init_optimizer=True + bf16 raises ValueError Consumer side (AutoConfig.from_pretrained): - test_load_precision_passed_to_autoconfig_from_pretrained: torch_dtype kwarg receives the configured model_load_dtype. Tests follow the test_precision_types / test_precision_validation_invalid patterns the reviewer flagged as templates. Signed-off-by: Mingyu Yang <[email protected]>
1 of 2 tasks
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do ?
Adds a configurable
dtensor_cfg.load_precisionknob so reference/teacher DTensor workers can load model weights at a non-fp32 precision (e.g. bf16), cutting initialization time and resident parameter memory. Default remains fp32, so existing configs are unchanged.Issues
None — quality-of-life / memory optimization.
Usage
Add
load_precisionunderdtensor_cfgin any config that needs it(typically the reference/teacher worker, where master weights aren't
required):
Before your PR is "Ready for review"
Pre checks:
Additional Information
Motivation. When the policy/teacher worker only needs forward passes (no optimizer state, no master-weight tracking), holding the full model in fp32 wastes ~2× the memory needed for activations and intermediate tensors. On a 14B–32B teacher this is the difference between fitting in a single shard and needing extra TP/PP. Letting users opt into bf16 for the load reclaims that headroom without affecting training workers.
Backwards compatibility. load_precision defaults to "float32", so behavior is unchanged for every existing config.
One subtle behavior change. Inside setup_model_and_optimizer, the torch_dtype passed to model_class.from_pretrained(...) was previously str(model_config.torch_dtype) (a string like "torch.float32"). It now passes the torch.dtype object directly (model_load_dtype). nemo_automodel.from_pretrained accepts both forms, but flagging it here in case it matters for a downstream consumer.
Files touched.