Skip to content

fix(hgt): numpy 路径三处改用相对导入(修 vendored ModuleNotFoundError)#17

Merged
Ayleovelle merged 1 commit into
mainfrom
fix/hgt-relative-imports
Jun 15, 2026
Merged

fix(hgt): numpy 路径三处改用相对导入(修 vendored ModuleNotFoundError)#17
Ayleovelle merged 1 commit into
mainfrom
fix/hgt-relative-imports

Conversation

@Ayleovelle

@Ayleovelle Ayleovelle commented Jun 15, 2026

Copy link
Copy Markdown
Owner

问题

sylanne_core/compute/hgt.pyforward() 里三处函数内导入用了绝对路径 from sylanne_core.compute.hgt_numpy import ...(808/828/901)。本仓里 sylanne_core 是顶层包,能跑;但这份 SDK 被下游插件 vendored 成 sylanne_alpha._engine.sylanne_core 后,绝对名 sylanne_core 不再指向自身,干净环境(无 editable 安装顶名)会 ModuleNotFoundError。下游 PR review(Gemini,HIGH)实测暴露。

修复

改用相对导入 from .hgt_numpy import ...,与 compute/ 包内其余 65 处导入习惯一致(全相对),无论是否顶层都正确解析。

验证

  • 语法 OK
  • 强制 _use_numpy=True 真跑 forward(),三处 numpy 路径全执行、输出维度正确
  • 全量 500 passed 零回归

Summary by Sourcery

Bug Fixes:

  • Replace absolute imports of numpy helper functions in HGT forward() with relative imports so vendored SDKs no longer raise ModuleNotFoundError.

hgt.py 的 forward() 里三处函数内导入写的是绝对路径
from sylanne_core.compute.hgt_numpy import ...(808/828/901)。在本仓
(sylanne_core 是顶层包)能跑,但这份 SDK 被下游插件 vendored 成
sylanne_alpha._engine.sylanne_core 后,绝对名 sylanne_core 不再指向自身,
干净环境(无 editable 安装顶名)会 ModuleNotFoundError。下游 PR review
(Gemini,HIGH)实测暴露。

改成相对导入 from .hgt_numpy import ...,与 compute/ 包内其余 65 处导入
习惯一致(全相对),无论是否顶层都正确解析。

验证:语法 OK;强制 _use_numpy=True 真跑 forward(),三处 numpy 路径全
执行、输出维度正确;全量 500 passed 零回归。
@sourcery-ai

sourcery-ai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR fixes numpy-related imports in hgt.forward() by switching three absolute imports of hgt_numpy helpers to relative imports, aligning with the rest of the compute package and making the module robust when vendored under a different top-level package name.

File-Level Changes

Change Details Files
Use relative imports for numpy helper functions in hgt.forward() to avoid ModuleNotFoundError when the package is vendored under a different top-level name.
  • Replaced absolute import of numpy_type_expert_forward with a relative import inside the _use_numpy guarded branch of the type-expert FFN stage.
  • Replaced absolute import of numpy_multi_head_attention with a relative import inside the _use_numpy guarded branch of the attention stage.
  • Replaced absolute import of numpy_moe_forward with a relative import inside the _use_numpy guarded branch of the MoE stage.
sylanne_core/compute/hgt.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions

Copy link
Copy Markdown

⚠️ 代码质量检查报告

发现部分文件需要格式化或存在代码问题,建议在本地运行 ruff format .ruff check --fix .

🖌️ 格式化: 9 个文件被重新格式化 (未变更: 80)
🛡️ 代码检查: 发现 6 个问题

  • 🛠️ 已自动修复: 4
  • ❌ 剩余未修复: 2
🔍 错误详情

```textF841 Local variable h is assigned to but never used
--> training/train_model.py:121:9
|
119 | rng = np.random.RandomState(0)
120 | d = self.d_model
121 | h = self.n_heads
| ^
122 | dh = self.d_head
123 | ff = self.d_ff
|
help: Remove assignment to unused variable `h`

F841 Local variable dh is assigned to but never used
--> training/train_model.py:122:9
|
120 | d = self.d_model
121 | h = self.n_heads
122 | dh = self.d_head
| ^^
123 | ff = self.d_ff
|
help: Remove assignment to unused variable dh

Found 6 errors (4 fixed, 2 remaining).
No fixes available (2 hidden fixes can be enabled with the --unsafe-fixes option).

</details>

@github-actions

Copy link
Copy Markdown

💩 屎山代码检测报告 允许合并

🎯 本次检测概览

「屎山刚开始发酵,臭味初显,但还能抢救」

维度 数据
屎山指数 41.26 / 100
屎山等级 轻度屎山级
检测时间 2026/6/15 08:57:13

🎭 整体印象

臭气扑鼻,建议佩戴口罩阅读

🧭 下一步

这代码像个叛逆期的青少年,需要适当管教才能成才


📥 详细数据

fuck-u-code 自动检测 · 本评论不代表人类观点

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates absolute imports of sylanne_core.compute.hgt_numpy to relative imports (.hgt_numpy) within sylanne_core/compute/hgt.py. There are no review comments, and I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@sourcery-ai sourcery-ai Bot 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.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Ayleovelle Ayleovelle merged commit 4d946eb into main Jun 15, 2026
7 of 8 checks passed
@Ayleovelle Ayleovelle deleted the fix/hgt-relative-imports branch June 15, 2026 12:42
Ayleovelle added a commit to Ayleovelle/astrbot_plugin_sylanne that referenced this pull request Jun 15, 2026
vendored 的 compute/hgt.py forward() 三处函数内导入是绝对 from
sylanne_core.compute.hgt_numpy(808/828/901),在干净部署环境(无 editable
顶名 sylanne_core)会 ModuleNotFoundError。已在上游 canonical 改成相对
from .hgt_numpy(PR Ayleovelle/SylannEngine#17,500 passed),此处把干净文件
surgical 同步回 vendored(保 CRLF,去 CRLF 后两文件完全一致)。

实测:vendored 相对导入在 sylanne_alpha._engine.sylanne_core.compute.hgt
路径下正确解析,不再依赖顶层 sylanne_core;全量 573 passed。
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