Fix(rng): use fixed seed for deterministic LoRA init#141
Merged
kilinchange merged 1 commit intomasterfrom Apr 10, 2026
Merged
Conversation
kilinchange
requested changes
Apr 10, 2026
example/llama3/main.cc
Outdated
| nn::lora::PrintLoRASummary(model, rank.GlobalRank()); | ||
| } | ||
|
|
||
| model->To(device); |
Collaborator
There was a problem hiding this comment.
这个挪位置是因为 normal 只有 cpu 实现,所以要在 cpu 上先初始化吗?但为什么之前不需要呢?
Contributor
Author
There was a problem hiding this comment.
CPU RNG 和 GPU RNG 是两套状态,而且采样设备也不一样,所以这两条路径下 LoRA 初值不同。我们固定的是 CPU RNG,所以要把 lora 初始化放到 CPU 上做
Collaborator
There was a problem hiding this comment.
但我们现在 normal 的实现是先在 cpu 生成,然后拷贝到 gpu 上(如果输入是 gpu tensor 的话),所以理论上这个的位置对于现在是不会有影响的吧?
Contributor
Author
There was a problem hiding this comment.
确实,实验了一下不影响。但我觉得这个改动可以留着,语义上都在CPU初始化也挺合理
Collaborator
There was a problem hiding this comment.
这里理论上我们应该补齐 cuda normal 实现,所以 cpu/cuda 初始化都是可以的,我建议这个 pr 先不引入不必要改动,可以等之后抽象出 Generator 抽象后再看下怎么放更合适
Replace std::random_device with 42 + omp_get_thread_num() to ensure reproducible LoRA initialization across runs.
kilinchange
approved these changes
Apr 10, 2026
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.
Replace std::random_device with 42 + omp_get_thread_num() to ensure reproducible LoRA initialization across runs.