Skip to content

Fix UnBoundLocalError in clm_collator.py #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 14, 2025
Merged

Conversation

c8ef
Copy link
Contributor

@c8ef c8ef commented Apr 7, 2025

What does this PR do?

I tried running the example mentioned in the readme, but encountered the error "local variable cp_rank referenced before assignment." After applying the patch, the example ran successfully.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guidelines?
  • Did you write any new necessary tests?
  • Did you log the throughput and loss you get to ensure the PR works as expected in actual training?
  • Did you log the memory usage? you can use this tool to understand the memory usage breakdown in nanotron.
  • If you modified anything related to checkpoints, did you verify that saving and reloading checkpoints still works correctly?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@c8ef
Copy link
Contributor Author

c8ef commented Apr 7, 2025

Hi @NouamaneTazi, could you please take a look at this patch?

Copy link
Member

@NouamaneTazi NouamaneTazi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thx :D

@c8ef
Copy link
Contributor Author

c8ef commented Apr 11, 2025

Thanks for the review! If the pull request looks good and doesn't need any further revisions, could you please help me merge it?

@NouamaneTazi NouamaneTazi changed the base branch from main to dev April 14, 2025 14:19
@NouamaneTazi NouamaneTazi merged commit 0dbf24d into huggingface:dev Apr 14, 2025
@c8ef c8ef deleted the patch-1 branch April 14, 2025 14:43
NouamaneTazi added a commit that referenced this pull request Apr 18, 2025
* can only merge to main from dev

* Fix UnBoundLocalError in `clm_collator.py` (#339)

* Update clm_collator.py

* can only merge to main from dev (#348)

---------

Co-authored-by: Nouamane Tazi <[email protected]>

* fix init and init scaling factor and run evals in background (#349)

* InitScalingMethod

* InitScalingMethod

* run evals in background (#352)

* eval

* try adding lightevalrunner to trainer

* amend

* amend

* amend

* amend

* amend

* amend

* .

* amend

* amend

* .

* qos to low

* add nanotron_path

* some fix: logs, and config

* cp instead of sync

* eval_interval

* serialize sanity checks

* add output dir and s3_save path in the config

* fix s3 only if define

* fixes

---------

Co-authored-by: elie <[email protected]>
Co-authored-by: “eliebak” <[email protected]>

---------

Co-authored-by: elie <[email protected]>
Co-authored-by: “eliebak” <[email protected]>

---------

Co-authored-by: Connector Switch <[email protected]>
Co-authored-by: elie <[email protected]>
Co-authored-by: “eliebak” <[email protected]>
NouamaneTazi added a commit that referenced this pull request Apr 23, 2025
* can only merge to main from dev (#348)

* move moe from qwen modeling to src/nn

* add groupedmlp

* add token permute and unpermute

* fix num_tokens_per_expert counting < num_experts

* fix init and init scaling factor and run evals in background (#353)

* can only merge to main from dev

* Fix UnBoundLocalError in `clm_collator.py` (#339)

* Update clm_collator.py

* can only merge to main from dev (#348)

---------

Co-authored-by: Nouamane Tazi <[email protected]>

* fix init and init scaling factor and run evals in background (#349)

* InitScalingMethod

* InitScalingMethod

* run evals in background (#352)

* eval

* try adding lightevalrunner to trainer

* amend

* amend

* amend

* amend

* amend

* amend

* .

* amend

* amend

* .

* qos to low

* add nanotron_path

* some fix: logs, and config

* cp instead of sync

* eval_interval

* serialize sanity checks

* add output dir and s3_save path in the config

* fix s3 only if define

* fixes

---------

Co-authored-by: elie <[email protected]>
Co-authored-by: “eliebak” <[email protected]>

---------

Co-authored-by: elie <[email protected]>
Co-authored-by: “eliebak” <[email protected]>

---------

Co-authored-by: Connector Switch <[email protected]>
Co-authored-by: elie <[email protected]>
Co-authored-by: “eliebak” <[email protected]>

* inference qwen moe seems to work

inference seems good rn

* update readme

* fix router's weight initialization and wrong hidden size for non-moe mlp in qwen

* add source for router weight and router logits in float32

* fixes

* .

* .

* add parametrize grouped mlp in column and row linear

* add logging per-param grad norm

* fix conversation fail due to buffer on cpu

* config_qwen

* .

* .

* fix moe convert config

---------

Co-authored-by: Nouamane Tazi <[email protected]>
Co-authored-by: Connector Switch <[email protected]>
Co-authored-by: elie <[email protected]>
Co-authored-by: “eliebak” <[email protected]>
Co-authored-by: zzhhjjj <[email protected]>
Co-authored-by: nouamanetazi <[email protected]>
garongkim pushed a commit to garongkim/nanotron that referenced this pull request Jun 2, 2025
* can only merge to main from dev (huggingface#348)

* move moe from qwen modeling to src/nn

* add groupedmlp

* add token permute and unpermute

* fix num_tokens_per_expert counting < num_experts

* fix init and init scaling factor and run evals in background (huggingface#353)

* can only merge to main from dev

* Fix UnBoundLocalError in `clm_collator.py` (huggingface#339)

* Update clm_collator.py

* can only merge to main from dev (huggingface#348)

---------

Co-authored-by: Nouamane Tazi <[email protected]>

* fix init and init scaling factor and run evals in background (huggingface#349)

* InitScalingMethod

* InitScalingMethod

* run evals in background (huggingface#352)

* eval

* try adding lightevalrunner to trainer

* amend

* amend

* amend

* amend

* amend

* amend

* .

* amend

* amend

* .

* qos to low

* add nanotron_path

* some fix: logs, and config

* cp instead of sync

* eval_interval

* serialize sanity checks

* add output dir and s3_save path in the config

* fix s3 only if define

* fixes

---------

Co-authored-by: elie <[email protected]>
Co-authored-by: “eliebak” <[email protected]>

---------

Co-authored-by: elie <[email protected]>
Co-authored-by: “eliebak” <[email protected]>

---------

Co-authored-by: Connector Switch <[email protected]>
Co-authored-by: elie <[email protected]>
Co-authored-by: “eliebak” <[email protected]>

* inference qwen moe seems to work

inference seems good rn

* update readme

* fix router's weight initialization and wrong hidden size for non-moe mlp in qwen

* add source for router weight and router logits in float32

* fixes

* .

* .

* add parametrize grouped mlp in column and row linear

* add logging per-param grad norm

* fix conversation fail due to buffer on cpu

* config_qwen

* .

* .

* fix moe convert config

---------

Co-authored-by: Nouamane Tazi <[email protected]>
Co-authored-by: Connector Switch <[email protected]>
Co-authored-by: elie <[email protected]>
Co-authored-by: “eliebak” <[email protected]>
Co-authored-by: zzhhjjj <[email protected]>
Co-authored-by: nouamanetazi <[email protected]>
NouamaneTazi added a commit that referenced this pull request Jun 23, 2025
* can only merge to main from dev

* Fix UnBoundLocalError in `clm_collator.py` (#339)

* Update clm_collator.py

* can only merge to main from dev (#348)

---------

Co-authored-by: Nouamane Tazi <[email protected]>

* fix init and init scaling factor and run evals in background (#349)

* InitScalingMethod

* InitScalingMethod

* run evals in background (#352)

* eval

* try adding lightevalrunner to trainer

* amend

* amend

* amend

* amend

* amend

* amend

* .

* amend

* amend

* .

* qos to low

* add nanotron_path

* some fix: logs, and config

* cp instead of sync

* eval_interval

* serialize sanity checks

* add output dir and s3_save path in the config

* fix s3 only if define

* fixes

---------

Co-authored-by: elie <[email protected]>
Co-authored-by: “eliebak” <[email protected]>

---------

Co-authored-by: elie <[email protected]>
Co-authored-by: “eliebak” <[email protected]>

* [Feature] Implement CUDA event-based timing for improved GPU performa… (#346)

* [Feature] Implement CUDA event-based timing for improved GPU performance measurement

* can only merge to main from dev (#348)

* Fix timer decorator logic: Support both CPU and CUDA timers and update docs

* Fix timer decorator logic: support both CPU and CUDA; update docs

---------

Co-authored-by: Kabir Grewal <[email protected]>
Co-authored-by: Nouamane Tazi <[email protected]>
Co-authored-by: Kabir Grewal <[email protected]>

* amend previous pr (#354)

* MoE without token dropping (#355)

* can only merge to main from dev (#348)

* move moe from qwen modeling to src/nn

* add groupedmlp

* add token permute and unpermute

* fix num_tokens_per_expert counting < num_experts

* fix init and init scaling factor and run evals in background (#353)

* can only merge to main from dev

* Fix UnBoundLocalError in `clm_collator.py` (#339)

* Update clm_collator.py

* can only merge to main from dev (#348)

---------

Co-authored-by: Nouamane Tazi <[email protected]>

* fix init and init scaling factor and run evals in background (#349)

* InitScalingMethod

* InitScalingMethod

* run evals in background (#352)

* eval

* try adding lightevalrunner to trainer

* amend

* amend

* amend

* amend

* amend

* amend

* .

* amend

* amend

* .

* qos to low

* add nanotron_path

* some fix: logs, and config

* cp instead of sync

* eval_interval

* serialize sanity checks

* add output dir and s3_save path in the config

* fix s3 only if define

* fixes

---------

Co-authored-by: elie <[email protected]>
Co-authored-by: “eliebak” <[email protected]>

---------

Co-authored-by: elie <[email protected]>
Co-authored-by: “eliebak” <[email protected]>

---------

Co-authored-by: Connector Switch <[email protected]>
Co-authored-by: elie <[email protected]>
Co-authored-by: “eliebak” <[email protected]>

* inference qwen moe seems to work

inference seems good rn

* update readme

* fix router's weight initialization and wrong hidden size for non-moe mlp in qwen

* add source for router weight and router logits in float32

* fixes

* .

* .

* add parametrize grouped mlp in column and row linear

* add logging per-param grad norm

* fix conversation fail due to buffer on cpu

* config_qwen

* .

* .

* fix moe convert config

---------

Co-authored-by: Nouamane Tazi <[email protected]>
Co-authored-by: Connector Switch <[email protected]>
Co-authored-by: elie <[email protected]>
Co-authored-by: “eliebak” <[email protected]>
Co-authored-by: zzhhjjj <[email protected]>
Co-authored-by: nouamanetazi <[email protected]>

* Nouamane/lighteval (#356)

* InitScalingMethod

* InitScalingMethod

* eval

* try adding lightevalrunner to trainer

* amend

* amend

* amend

* amend

* amend

* amend

* .

* amend

* amend

* .

* qos to low

* add nanotron_path

* some fix: logs, and config

* cp instead of sync

* eval_interval

* serialize sanity checks

* add output dir and s3_save path in the config

* fix s3 only if define

* fixes

* add requeue

* add wandb with lighteval and fix eval interval

* fix this little space :(

* folder_path should always have s3 when using s3 (fix consumed tokens issue)

* config qwen

* .

---------

Co-authored-by: elie <[email protected]>
Co-authored-by: “eliebak” <[email protected]>

* SmoLM3 training 🚀 (#375)

* InitScalingMethod

* InitScalingMethod

* eval

* try adding lightevalrunner to trainer

* amend

* amend

* amend

* amend

* amend

* amend

* .

* amend

* amend

* .

* qos to low

* add nanotron_path

* some fix: logs, and config

* cp instead of sync

* eval_interval

* serialize sanity checks

* add output dir and s3_save path in the config

* fix s3 only if define

* fixes

* add requeue

* add wandb with lighteval and fix eval interval

* fix this little space :(

* folder_path should always have s3 when using s3 (fix consumed tokens issue)

* fix resuming with new data mixture

* offsets must be in samples not tokens

* sanity check local files when dataset_read_path

* better error for new stage

* rmsnorm

* sliding window

* causal SWA

* Revert "rmsnorm"

This reverts commit 17dad0a.

* rope_seq_len_interpolation_factor

* logmixin for intermediate tensors + CP + consumed_token shenanigans when resuming training (#365)

* logmixin

* context parallelism (llama3 ring attn) + consumed_token shenanigans (#366)

* training works

* llama3 ring attn

* llama3 ring attn

* llama3 ring attn

* fix position_ids (make them global)

* rope_seq_len_interpolation_factor assert

* .

* .

* fix rope and cp_pg

* fixed consumed_tokens log

---------

Co-authored-by: elie <[email protected]>
Co-authored-by: “eliebak” <[email protected]>

---------

Co-authored-by: Connector Switch <[email protected]>
Co-authored-by: elie <[email protected]>
Co-authored-by: “eliebak” <[email protected]>
Co-authored-by: grewalsk <[email protected]>
Co-authored-by: Kabir Grewal <[email protected]>
Co-authored-by: Kabir Grewal <[email protected]>
Co-authored-by: XλRI-U5 <[email protected]>
Co-authored-by: zzhhjjj <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants