Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 155 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 13 additions & 9 deletions app/docs/ai/MoE/moe-update.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Theory of MoE
title: "Theory of MoE"
description: ""
date: "2025-10-05"
tags:
Expand All @@ -16,17 +16,21 @@ docId: db3qwg25h6l0bh8f2sdabdqc
给定正的常数 $c_1, c_2$,我们定义:

- $x = \Omega(y)$,如果 $x > c_2 |y|$;
- $x = \Theta(y)$,如果 $c_1 |y| < x < c_2 |y|$;
- $x = O(y)$,如果 $x < c_1 |y|$;
- $x = o(y)$,如果 $\frac{x}{y} \to 0$。
- O(y):上界,表示“不会比 y 增长得更快”。
- Ω(y):下界,表示“至少和 y 一样快”。
- Θ(y):上下界都在 y 的数量级内,表示“和 y 同阶”。
- o(y):严格比 y 小得多,最终会趋近于 0。
- $x = \Theta(y)$,如果 $c_1 |y| \lt x \lt c_2 |y|$;
- $x = O(y)$,如果 $x \lt c_1 |y|$;
- $x = o(y)$,如果 $\dfrac{x}{y} \to 0$。

其中:

- $O(y)$:上界,表示“不会比 $y$ 增长得更快”。
- $\Omega(y)$:下界,表示“至少和 $y$ 一样快”。
- $\Theta(y)$:上下界都在 $y$ 的数量级内,表示“和 $y$ 同阶”。
- $o(y)$:严格比 $y$ 小得多,最终会趋近于 $0$。

## **重要假设**:

1. 这个文章只想给出闭式遗忘公式,所以直接简化成线性模型。$f(X)=X^⊤w,w∈R^d$
1. 这个文章只想给出闭式遗忘公式,所以直接简化成线性模型。$f(X)=X^{\top}w,\; w\in \mathbb{R}^d$

2. 这个文章只讨论task-wised的路由方法,数据生成的时候每份数据只加入了一个信号数据,其余都是正态分布噪声。目的也是为了简化模型,然后在实际工程应用中,token会被隐式的送到各个experts,而不采用人为设定的方式。

> ### 数据集生成规则
Expand Down
41 changes: 41 additions & 0 deletions mdx-components.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
import Image from "next/image";
import type { ImageProps } from "next/image";
import defaultMdxComponents from "fumadocs-ui/mdx";
import type { MDXComponents } from "mdx/types";
import type { ComponentPropsWithoutRef } from "react";

type MdxImageProps = ComponentPropsWithoutRef<"img"> & {
src?: ImageProps["src"];
width?: number | string;
height?: number | string;
};

function MdxImage({ src, alt = "", width, height, ...rest }: MdxImageProps) {
if (!src) {
return (
<img
src={src as string}
alt={alt}
width={width}
height={height}
{...rest}
/>
);
Comment on lines +15 to +23
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

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

The logic is inverted. When src is falsy, the code renders an img element with src={src as string}, which will result in an empty or undefined src attribute. The condition should be if (!src) with an early return or error handling, not rendering an img with the falsy src value.

Suggested change
return (
<img
src={src as string}
alt={alt}
width={width}
height={height}
{...rest}
/>
);
return null;

Copilot uses AI. Check for mistakes.
}
const numericWidth = typeof width === "string" ? Number(width) : width;
const numericHeight = typeof height === "string" ? Number(height) : height;

if (!Number.isFinite(numericWidth) || !Number.isFinite(numericHeight)) {
// fallback: 当 width/height 不是可解析数值时,直接使用原生 <img>
return <img src={src ?? ""} alt={alt ?? ""} {...rest} />;
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

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

The condition checks if either width or height is not finite, but the fallback doesn't pass the width and height props to the img element. This could result in missing dimensions that were intended to be applied.

Suggested change
return <img src={src ?? ""} alt={alt ?? ""} {...rest} />;
return <img src={src ?? ""} alt={alt ?? ""} width={width} height={height} {...rest} />;

Copilot uses AI. Check for mistakes.
}

return (
<Image
src={src ?? ""}
alt={alt ?? ""}
width={numericWidth}
height={numericHeight}
Comment on lines +37 to +38
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

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

The Next.js Image component requires both width and height to be defined numbers when using static imports or external URLs. If either numericWidth or numericHeight is undefined or NaN after conversion, this will cause a runtime error. Add validation to ensure both values are valid numbers before passing to the Image component.

Copilot uses AI. Check for mistakes.
{...rest}
/>
);
}

export function getMDXComponents(components?: MDXComponents): MDXComponents {
return {
...defaultMdxComponents,
img: MdxImage,
...components,
};
}
5 changes: 4 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// next.config.mjs
import { createMDX } from "fumadocs-mdx/next";
import createNextIntlPlugin from "next-intl/plugin";
import { remarkImage } from "fumadocs-core/mdx-plugins";

const withMDX = createMDX({
configPath: "source.config.ts",
mdxOptions: {
remarkPlugins: [[remarkImage, { onError: "ignore", external: true }]],
},
});

const withNextIntl = createNextIntlPlugin("./i18n.ts");

/** @type {import('next').NextConfig} */
Expand Down