Skip to content
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

[docs] update set-seed #3228

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

[docs] update set-seed #3228

wants to merge 2 commits into from

Conversation

faaany
Copy link
Contributor

@faaany faaany commented Nov 8, 2024

What does this PR do?

The current set-seed in documentation only includes the cuda part, which is out-dated. This PR updates it with the current implementation.

@muellerzr

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@faaany
Copy link
Contributor Author

faaany commented Nov 21, 2024

@muellerzr @BenjaminBossan

Copy link
Member

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

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

Thanks for updating the docs.

IMO, it would also be fine to remove the code snippet completely (as it's just a matter of time until it gets out of date again) and just explain in words what's happening.

@faaany
Copy link
Contributor Author

faaany commented Nov 22, 2024

Thanks for updating the docs.

IMO, it would also be fine to remove the code snippet completely (as it's just a matter of time until it gets out of date again) and just explain in words what's happening.

I think code is easier to read and understand. Only using cuda is a bit unfair. Maybe I can update other devices in a comment?

@BenjaminBossan
Copy link
Member

I think code is easier to read and understand. Only using cuda is a bit unfair. Maybe I can update other devices in a comment?

My main concern is mostly the example and the actual code getting out of sync. It's not a big deal, would just be nice to prevent it.

Copy link
Collaborator

@muellerzr muellerzr left a comment

Choose a reason for hiding this comment

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

Thanks, there is always a fear of what would happen if code gets out of sync, esp as even this code doesn't quite fully align to what we're up to. (e.g. there's now a by_index).

While it's not per-se "fair", I'm not sure if it's more or less readable now than before for our docs. It is a concept guide, so we can show more code. Just wish we could show the source itself.

I think we could get by just saying:

    random.seed(seed)
    np.random.seed(seed)
    torch.manual_seed(seed)
    torch.cuda.manual_seed_all(seed) # or torch.npu.manual_seed_all, etc
    # ^^ safe to call this function even if cuda/backend is not available
    if is_torch_xla_available():
        xm.set_rng_state(seed)

Since we care more about manual_seed_all than the backend specifically

@faaany
Copy link
Contributor Author

faaany commented Nov 26, 2024

Thanks for the feedback! Agree. Code looks much cleaner now. @muellerzr @BenjaminBossan

Copy link
Collaborator

@muellerzr muellerzr left a comment

Choose a reason for hiding this comment

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

Thanks!

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.

4 participants