Skip to content

[fix]: fix moe.hpp load from file bug.#1780

Merged
ouqingliang merged 2 commits intomainfrom
fix-bug-oql
Jan 4, 2026
Merged

[fix]: fix moe.hpp load from file bug.#1780
ouqingliang merged 2 commits intomainfrom
fix-bug-oql

Conversation

@ouqingliang
Copy link
Contributor

What does this PR do?

Fixes # (issue)

Before submitting

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ouqingliang, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a bug in moe.hpp related to how file paths were handled during load operations. The core change involves refactoring the prefix path variable from a class member to a locally scoped variable within the methods that utilize it, ensuring proper path construction and usage. This change improves the reliability of file loading and saving, and also enhances logging by displaying the specific path being accessed.

Highlights

  • Refactored Path Variable Scope: The prefix path variable, previously a member of the AMX_MOE_TP class, has been refactored to be a local std::filesystem::path variable within the constructor and the file loading logic, ensuring correct scoping and initialization.
  • Enhanced Load Path Logging: The printf statement indicating 'TP Load from file' now includes the actual config.path being loaded, providing more informative output for debugging and monitoring.
  • Updated Lambda Capture: A lambda function used for saving weights was updated to explicitly capture the prefix variable, which became necessary after its scope was changed from a class member to a local variable.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request fixes a bug related to loading from a file in moe.hpp by changing the prefix variable from a class member to a local variable. This correctly resolves an issue where the member variable was used without being initialized in some code paths. The changes are logical and address the bug effectively. I have a couple of suggestions to improve maintainability and code consistency.

Comment on lines +261 to +262
std::filesystem::path prefix = config_.path;
prefix = prefix / ("_layer_" + std::to_string(config_.layer_idx)) / ("_numa_" + std::to_string(tp_part_idx));
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This logic to construct the prefix path is duplicated from lines 145-146 within the same function. To improve maintainability and avoid redundancy, consider defining and initializing the prefix variable once at the beginning of the load_weights function, before the if (config_.quant_config.bits == 0) block.

this->weights_loaded = true;
} else if (config.path != "") {
printf("TP Load from file\n");
printf("TP Load from file %s\n", config.path.c_str());
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For consistency with the logging style in this file (e.g., lines 148, 265), it's better to use std::cout instead of printf. This also avoids mixing C-style I/O with C++ streams and leverages C++ features more effectively.

      std::cout << "TP Load from file " << config.path << std::endl;

@ouqingliang ouqingliang merged commit dc6394e into main Jan 4, 2026
7 of 9 checks passed
@ouqingliang ouqingliang deleted the fix-bug-oql branch January 4, 2026 11:33
JimmyPeilinLi added a commit that referenced this pull request Jan 20, 2026
* fix pypi cuda install (#1763)

* Update release-pypi.yml (#1764)

* fix cuda wheel build (#1766)

* Cli (#1765)

* [feat]: add custom option for kt run

* [feat]: depth 3

* [docs]: add kt-cli doc and update corresponding website (#1768)

* Remove kt-kernel-cuda, kt-kernel uses the version with cuda (#1769)

* Update release-pypi.yml (#1770)

* bump to 0.5.0.post1 (#1771)

* [ci]: Patch ci (#1772)

* [docs]: add kt-cli doc and update corresponding website

* [feat]: update issue template

* [fix]: fix moe hpp bug. (#1780)

fix moe hpp init bug.

* Fix moe bug. (#1783)

* [fix]: fix moe.hpp load from file bug.

* [fix]: fix all moe hpp init bug.

* [fix]: fix moe & awq-moe ug.

* [feat](kt-sft-refactor): load from huggingface safetensor file

* [fix]: fix bugs for activation, sft forward and backward

---------

Co-authored-by: Jianwei Dong <dongjw24@mails.tsinghua.edu.cn>
Co-authored-by: ErvinXie <ervinxie@qq.com>
Co-authored-by: ZiWei Yuan <yzwliam@126.com>
Co-authored-by: Oql <1692110604@qq.com>
Co-authored-by: mrhaoxx <mr.haoxx@gmail.com>
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.

1 participant