Skip to content

2026-spring-littleotherut-T2-2-1#186

Open
littleotherut wants to merge 8 commits into
InfiniTensor:masterfrom
littleotherut:2026-spring-littleotherut-T2-2-1
Open

2026-spring-littleotherut-T2-2-1#186
littleotherut wants to merge 8 commits into
InfiniTensor:masterfrom
littleotherut:2026-spring-littleotherut-T2-2-1

Conversation

@littleotherut

Copy link
Copy Markdown
Contributor

2026春大赛训推赛道T2-2-1 中的 Generator 抽象设计。非报名正式参赛选手,最后几天尝试遵循任务要求做了一些很粗糙的设计,做了核心架构抽象和部分后端落地。
报告.pdf

@kilinchange kilinchange requested a review from chen2021673 July 13, 2026 08:33

// Process-wide default CPU generator (single shared random state source).
Generator &MutableDefaultCPUGenerator() {
static Generator generator(std::make_shared<CPUGeneratorImpl>());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CPU只创建了一个进程级 generator,在单进程多线程 DDP 场景下,各 rank 串行消费同一个进程级 RNG,拿到的随机数并不确定。建议在 DDP 模型 to device 后、第一次 forward 前,从 DP group rank 0 原地 broadcast 所有参数。

for (int64_t i = 0; i < num_elements; ++i) { data[i] = (values[i] < p) ? 0.0f : data[i] * scale; }

impl->MemcpyAsync(tensor->DataPtr(), data.data(), num_elements * sizeof(float),
device.IsCPU() ? core::MemcpyKind::kD2D : core::MemcpyKind::kH2D, impl->GetStream(device));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这也要SynchronizeStream一下吧

@chen2021673 chen2021673 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

统一 Generator 抽象、CPU/CUDA 实现、默认 Generator、seed/state 管理、算子接入以及测试框架都已经搭建起来,代码结构也比较清晰。可以继续补齐 CUDA Generator 未完成功能和对应测试。

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