Skip to content

[Feat] [CPU] glm_ocr: Add model support - #37597

Merged
mingfeima merged 17 commits into
sgl-project:mainfrom
yuchengliu1:glm_ocr
Nov 5, 2026
Merged

mingfeima merged 17 commits into
sgl-project:mainfrom
yuchengliu1:glm_ocr

Conversation

@yuchengliu1

@yuchengliu1 yuchengliu1 commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Enable GLM_OCR on XEON.

  1. add RGB support to AMX Conv3d kernel
  2. add mix dtype support to Layernorm
  3. support TP=6 in frontend.

The input/weight/bias of Layernorm support fp16/bf16/fp32 and these three dtypes are independent of one another.
output/gate/residual has the same dtype with input.
residual and bias is optional.

Accuracy (using lmms_eval as cookbook advised):

Tasks Filter n-shot Metric Value Stderr Stderr_CLT
ocrbench none 0 ocrbench_accuracy ↑ 0.835 ± N/A 0.0117

CI States

Latest PR Test (Base): 🚫 Run #41797587595
Latest PR Test (Extra): ❌ Run #41797587468
Latest PR Test (AMD ROCm 10): ❌ Run #41797587439

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

@mingfeima mingfeima added intel cpu cpu backend performance optimization labels Sep 15, 2026
@mingfeima
mingfeima marked this pull request as draft September 15, 2026 07:40
@mingfeima

Copy link
Copy Markdown
Collaborator

your local base is too old. rebase to master.

@yuchengliu1

Copy link
Copy Markdown
Contributor Author

I have rebase it to master

using weight_t = scalar_t;
if (bias.has_value()) {
AT_DISPATCH_REDUCED_FLOATING_TYPES_AND(at::kFloat, bias.value().scalar_type(), "layernorm_bias", [&] {
using bias_t = scalar_t;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

bias can either be float32 or the same dtype with input.

aka. you will not likely to have input bf16 and bias f16.

what is the real use case in your concerned models?

can you make a table listing :

  • model name
  • input type
  • weight type
  • bias type

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The input/weight/bias of Layernorm support fp16/bf16/fp32 and these three dtypes are independent of one another.
output/gate/residual has the same dtype with input.
residual and bias is optional.

@yuchengliu1 yuchengliu1 Sep 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The models of GLM series have text module and vision module, and they call the different norm OP (They will finally use the kernel modified in this PR).
The type value in table means input_type/weight_type/bias_type.

Model  text module(RMSnorm) vision module(layernorm)
GLM4.x BF16/BF16/BF16 /
GLM4.xV/GLM_ocr FP16/FP16/FP16 BF16/FP32/FP32

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

therefore:

  • scalar_t (input) is either bf16 or fp16;
  • param_t (weight and bias) is either same as scalar_t or acc_t (fp32)

weight and bias must be the same dtype.

use CPU_DISPATCH_FLOATING_TYPES_EXT and AT_DISPATCH_BOOL

@yuchengliu1
yuchengliu1 marked this pull request as ready for review September 20, 2026 07:52
using weight_t = scalar_t;
if (bias.has_value()) {
AT_DISPATCH_REDUCED_FLOATING_TYPES_AND(at::kFloat, bias.value().scalar_type(), "layernorm_bias", [&] {
using bias_t = scalar_t;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

therefore:

  • scalar_t (input) is either bf16 or fp16;
  • param_t (weight and bias) is either same as scalar_t or acc_t (fp32)

weight and bias must be the same dtype.

use CPU_DISPATCH_FLOATING_TYPES_EXT and AT_DISPATCH_BOOL

@github-actions

This comment has been minimized.

@yuchengliu1 yuchengliu1 changed the title [CPU] enbale GLM_OCR [Feat][Intel Xeon] GLM_OCR: Add model support Oct 21, 2026
@github-actions

This comment has been minimized.

@yanbing-j yanbing-j left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM.

@mingfeima
mingfeima marked this pull request as ready for review October 29, 2026 07:59

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

Comment thread test/registered/cpu/test_norm.py Outdated
Comment on lines +632 to +650
atol = rtol = precision[dtype]
atol = rtol = 5e-2

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why we have to do this ?

Comment on lines -180 to +176
vsum2 = _mm512_dpbf16_ps(vsum2, va[col], va[col]);
vsum2 = _mm512_fmadd_ps(va0[col], va0[col], vsum2);
vsum2 = _mm512_fmadd_ps(va1[col], va1[col], vsum2);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

don't quite prefer this, but shouldn't be a big issue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We cannot assume the input is BF16, so I rewrote load and reduce here to support a wider range of input types.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@mingfeima mingfeima added the run-ci CI: run the baseline test suite on this PR label Nov 2, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@mingfeima

Copy link
Copy Markdown
Collaborator

@yuchengliu1 fix lint

@mingfeima
mingfeima merged commit 3e9ce43 into sgl-project:main Nov 5, 2026
152 of 165 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cpu cpu backend performance optimization intel Multi-modal multi-modal language model run-ci CI: run the baseline test suite on this PR sgl-kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants