Skip to content

Add torchao quant (int4/int8/fp8) to llama models - #1341

Merged
merrymercy merged 8 commits into
sgl-project:mainfrom
jerryzh168:enable-torchao
Sep 9, 2024
Merged

merrymercy merged 8 commits into
sgl-project:mainfrom
jerryzh168:enable-torchao

Conversation

@jerryzh168

@jerryzh168 jerryzh168 commented Sep 6, 2024 •

Copy link
Copy Markdown
Contributor

Summary:
We want to hack before we work on a proper solution

proper solution will be rewrite llama model with tensor parallelism: https://pytorch.org/docs/stable/distributed.tensor.parallel.html
(using DTensor underneath), trying to do it here: pytorch/ao#785

Test Plan:

python3 -m sglang.bench_latency --model meta-llama/Meta-Llama-3-8B --batch-size 1 --input 128 --output 8

max_total_num_tokens=432196
Warmup ...
Prefill. latency: 0.03214 s, throughput:   3983.19 token/s
Decode.  latency: 0.01383 s, throughput:     72.31 token/s
Decode.  latency: 0.01354 s, throughput:     73.88 token/s
Decode.  latency: 0.01338 s, throughput:     74.75 token/s
Decode.  latency: 0.01330 s, throughput:     75.17 token/s
Decode.  median latency: 0.01346 s, median throughput:     74.31 token/s
Total. latency:  0.086 s, throughput:   1531.66 token/s
Benchmark ...
Prefill. latency: 0.02514 s, throughput:   5092.40 token/s
Decode.  latency: 0.01337 s, throughput:     74.80 token/s
Decode.  latency: 0.01338 s, throughput:     74.74 token/s
Decode.  latency: 0.01339 s, throughput:     74.68 token/s
Decode.  latency: 0.01321 s, throughput:     75.68 token/s
Decode.  latency: 0.01295 s, throughput:     77.23 token/s
Decode.  median latency: 0.01337 s, median throughput:     74.77 token/s
Total. latency:  0.132 s, throughput:   1032.13 token/s

python3 -m sglang.bench_latency --model meta-llama/Meta-Llama-3-8B --batch-size 1 --input 128 --output 8 --torchao-config int4wo

max_total_num_tokens=505188
Warmup ...
Prefill. latency: 0.10929 s, throughput:   1171.18 token/s
Decode.  latency: 0.00790 s, throughput:    126.57 token/s
Decode.  latency: 0.00738 s, throughput:    135.54 token/s
Decode.  latency: 0.00724 s, throughput:    138.16 token/s
Decode.  latency: 0.00726 s, throughput:    137.71 token/s
Decode.  median latency: 0.00732 s, median throughput:    136.62 token/s
Total. latency:  0.139 s, throughput:    949.17 token/s
Benchmark ...
Prefill. latency: 0.10405 s, throughput:   1230.13 token/s
Decode.  latency: 0.00769 s, throughput:    129.96 token/s
Decode.  latency: 0.00725 s, throughput:    137.85 token/s
Decode.  latency: 0.00724 s, throughput:    138.11 token/s
Decode.  latency: 0.00731 s, throughput:    136.72 token/s
Decode.  latency: 0.00744 s, throughput:    134.47 token/s
Decode.  median latency: 0.00730 s, median throughput:    136.97 token/s
Total. latency:  0.163 s, throughput:    834.99 token/s

with compile
python3 -m sglang.bench_latency --model meta-llama/Meta-Llama-3-8B --batch-size 1 --input 128 --output 8 --enable-torch-compile

max_total_num_tokens=432196
Warmup ...
Prefill. latency: 0.03095 s, throughput:   4135.63 token/s
Decode.  latency: 0.01258 s, throughput:     79.49 token/s
Decode.  latency: 0.01250 s, throughput:     79.98 token/s
Decode.  latency: 0.01262 s, throughput:     79.22 token/s
Decode.  latency: 0.01246 s, throughput:     80.26 token/s
Decode.  median latency: 0.01254 s, median throughput:     79.73 token/s
Total. latency:  0.081 s, throughput:   1627.28 token/s
Benchmark ...
Prefill. latency: 0.02445 s, throughput:   5234.65 token/s
Decode.  latency: 0.01249 s, throughput:     80.09 token/s
Decode.  latency: 0.01245 s, throughput:     80.30 token/s
Decode.  latency: 0.01195 s, throughput:     83.65 token/s
Decode.  latency: 0.01170 s, throughput:     85.45 token/s
Decode.  latency: 0.01179 s, throughput:     84.85 token/s
Decode.  median latency: 0.01179 s, median throughput:     84.79 token/s
Total. latency:  0.120 s, throughput:   1131.80 token/s

python3 -m sglang.bench_latency --model meta-llama/Meta-Llama-3-8B --batch-size 1 --input 128 --output 8 --enable-torch-compile --torchao-config int4wo-128
max_total_num_tokens=506932
Warmup ...
Prefill. latency: 0.10922 s, throughput:   1171.92 token/s
Decode.  latency: 0.00739 s, throughput:    135.25 token/s
Decode.  latency: 0.00692 s, throughput:    144.58 token/s
Decode.  latency: 0.00673 s, throughput:    148.68 token/s
Decode.  latency: 0.00673 s, throughput:    148.68 token/s
Decode.  median latency: 0.00682 s, median throughput:    146.60 token/s
Total. latency:  0.137 s, throughput:    963.61 token/s
Benchmark ...
Prefill. latency: 0.10405 s, throughput:   1230.12 token/s
Decode.  latency: 0.00733 s, throughput:    136.34 token/s
Decode.  latency: 0.00689 s, throughput:    145.13 token/s
Decode.  latency: 0.00682 s, throughput:    146.59 token/s
Decode.  latency: 0.00677 s, throughput:    147.67 token/s
Decode.  latency: 0.00676 s, throughput:    147.85 token/s
Decode.  median latency: 0.00677 s, median throughput:    147.76 token/s
Total. latency:  0.159 s, throughput:    856.11 token/s

python3 -m sglang.bench_latency --model meta-llama/Meta-Llama-3-8B --batch-size 1 --input 128 --output 8 --enable-torch-compile --torchao-config int8wo

max_total_num_tokens=484068
Warmup ...
Prefill. latency: 0.05860 s, throughput:   2184.33 token/s
Decode.  latency: 0.00921 s, throughput:    108.52 token/s
Decode.  latency: 0.00883 s, throughput:    113.29 token/s
Decode.  latency: 0.00880 s, throughput:    113.69 token/s
Decode.  latency: 0.00868 s, throughput:    115.15 token/s
Decode.  median latency: 0.00881 s, median throughput:    113.49 token/s
Total. latency:  0.094 s, throughput:   1402.45 token/s
Benchmark ...
Prefill. latency: 0.05269 s, throughput:   2429.12 token/s
Decode.  latency: 0.00928 s, throughput:    107.80 token/s
Decode.  latency: 0.00892 s, throughput:    112.10 token/s
Decode.  latency: 0.00881 s, throughput:    113.53 token/s
Decode.  latency: 0.00870 s, throughput:    114.90 token/s
Decode.  latency: 0.00864 s, throughput:    115.68 token/s
Decode.  median latency: 0.00876 s, median throughput:    114.15 token/s
Total. latency:  0.123 s, throughput:   1102.80 token/s

python3 -m sglang.bench_latency --model meta-llama/Meta-Llama-3-8B --batch-size 1 --input 128 --output 8 --enable-torch-compile --torchao-config int8dq
max_total_num_tokens=432196
Warmup ...
Prefill. latency: 0.03086 s, throughput:   4147.16 token/s
Decode.  latency: 0.01249 s, throughput:     80.03 token/s
Decode.  latency: 0.01246 s, throughput:     80.29 token/s
Decode.  latency: 0.01275 s, throughput:     78.42 token/s
Decode.  latency: 0.01244 s, throughput:     80.39 token/s
Decode.  median latency: 0.01247 s, median throughput:     80.16 token/s
Total. latency:  0.081 s, throughput:   1629.54 token/s
Benchmark ...
Prefill. latency: 0.02428 s, throughput:   5270.99 token/s
Decode.  latency: 0.01250 s, throughput:     79.99 token/s
Decode.  latency: 0.01252 s, throughput:     79.87 token/s
Decode.  latency: 0.01260 s, throughput:     79.34 token/s
Decode.  latency: 0.01234 s, throughput:     81.02 token/s
Decode.  latency: 0.01236 s, throughput:     80.92 token/s
Decode.  median latency: 0.01241 s, median throughput:     80.56 token/s
Total. latency:  0.124 s, throughput:   1098.26 token/s

python3 -m sglang.bench_latency --model meta-llama/Meta-Llama-3-8B --batch-size 1 --input 128 --output 8 --enable-torch-compile --torchao-config fp8wo
# [rank0]: AssertionError: fp8e4nv data type is not supported on CUDA arch < 89

Reviewers:

Subscribers:

Tasks:

Tags:

Summary:
We want to hack before we work on a proper solution

proper solution will be rewrite llama model with tensor parallelism: https://pytorch.org/docs/stable/distributed.tensor.parallel.html
(using DTensor underneath), trying to do it here: pytorch/ao#785

Test Plan:
change `ENABLE_TORCHAO` to True/False in `python/sglang/srt/models/llama.py` to test the baseline v.s. torchao int4 weight only quant performance

python3 -m sglang.bench_latency --model meta-llama/Meta-Llama-3-8B --batch-size 1 --input 128 --output 8

```

max_total_num_tokens=432196
Warmup ...
Prefill. latency: 0.03214 s, throughput:   3983.19 token/s
Decode.  latency: 0.01383 s, throughput:     72.31 token/s
Decode.  latency: 0.01354 s, throughput:     73.88 token/s
Decode.  latency: 0.01338 s, throughput:     74.75 token/s
Decode.  latency: 0.01330 s, throughput:     75.17 token/s
Decode.  median latency: 0.01346 s, median throughput:     74.31 token/s
Total. latency:  0.086 s, throughput:   1531.66 token/s
Benchmark ...
Prefill. latency: 0.02514 s, throughput:   5092.40 token/s
Decode.  latency: 0.01337 s, throughput:     74.80 token/s
Decode.  latency: 0.01338 s, throughput:     74.74 token/s
Decode.  latency: 0.01339 s, throughput:     74.68 token/s
Decode.  latency: 0.01321 s, throughput:     75.68 token/s
Decode.  latency: 0.01295 s, throughput:     77.23 token/s
Decode.  median latency: 0.01337 s, median throughput:     74.77 token/s
Total. latency:  0.132 s, throughput:   1032.13 token/s

max_total_num_tokens=505188
Warmup ...
Prefill. latency: 0.10929 s, throughput:   1171.18 token/s
Decode.  latency: 0.00790 s, throughput:    126.57 token/s
Decode.  latency: 0.00738 s, throughput:    135.54 token/s
Decode.  latency: 0.00724 s, throughput:    138.16 token/s
Decode.  latency: 0.00726 s, throughput:    137.71 token/s
Decode.  median latency: 0.00732 s, median throughput:    136.62 token/s
Total. latency:  0.139 s, throughput:    949.17 token/s
Benchmark ...
Prefill. latency: 0.10405 s, throughput:   1230.13 token/s
Decode.  latency: 0.00769 s, throughput:    129.96 token/s
Decode.  latency: 0.00725 s, throughput:    137.85 token/s
Decode.  latency: 0.00724 s, throughput:    138.11 token/s
Decode.  latency: 0.00731 s, throughput:    136.72 token/s
Decode.  latency: 0.00744 s, throughput:    134.47 token/s
Decode.  median latency: 0.00730 s, median throughput:    136.97 token/s
Total. latency:  0.163 s, throughput:    834.99 token/s

Warmup ...
Prefill. latency: 0.05868 s, throughput:   2181.51 token/s
Decode.  latency: 0.04475 s, throughput:     22.35 token/s
Decode.  latency: 0.04463 s, throughput:     22.41 token/s
Decode.  latency: 0.04467 s, throughput:     22.39 token/s
Decode.  latency: 0.04478 s, throughput:     22.33 token/s
Decode.  median latency: 0.04471 s, median throughput:     22.37 token/s
Total. latency:  0.238 s, throughput:    555.78 token/s
Benchmark ...
Prefill. latency: 0.05274 s, throughput:   2427.22 token/s
Decode.  latency: 0.04463 s, throughput:     22.41 token/s
Decode.  latency: 0.04456 s, throughput:     22.44 token/s
Decode.  latency: 0.04453 s, throughput:     22.45 token/s
Decode.  latency: 0.04469 s, throughput:     22.38 token/s
Decode.  latency: 0.04457 s, throughput:     22.44 token/s
Decode.  median latency: 0.04457 s, median throughput:     22.44 token/s
Total. latency:  0.409 s, throughput:    332.13 token/s
```

Reviewers:

Subscribers:

Tasks:

Tags:
@zhyncs

zhyncs commented Sep 6, 2024

Copy link
Copy Markdown
Contributor

Hi @msaroufim @jerryzh168 Nice work! It looks like the CI failures are due to a missing torchao dependency. Could you please add it to https://github.com/sgl-project/sglang/blob/main/python/pyproject.toml? Thanks.

@merrymercy merrymercy 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.

Given the changes are very minimal. I feel that we can even merge this and start iteration. Here are a few thoughts on making it more clean.

  1. Add a new argument --enable-torchao similar to --enable-torch-compile here
    "--enable-torch-compile",
    .
  2. Alternatively, instead of adding --enable-torchao, we can add a new quantization format torchao-int4 here
    "--quantization",
  3. You can pass the above arguments to this global variable
    global_server_args_dict.update(
    {
    "disable_flashinfer": server_args.disable_flashinfer,
    "disable_flashinfer_sampling": server_args.disable_flashinfer_sampling,
    "triton_attention_reduce_in_fp32": server_args.triton_attention_reduce_in_fp32,
    "enable_mla": server_args.enable_mla,
    }
    )
    and read it in llama.py

Comment thread python/sglang/srt/models/llama.py Resolved
@zhyncs zhyncs self-assigned this Sep 6, 2024
@jerryzh168

jerryzh168 commented Sep 7, 2024 •

Copy link
Copy Markdown
Contributor Author

2. Alternatively, instead of adding --enable-torchao, we can add a new quantization format torchao-int4 here

@merrymercy thanks for the suggestions, I can start with https://github.com/pytorch/ao/blob/1ce7da941b311ef6ab416d9c7a22be20e65b7495/torchao/_models/llama/generate.py#L462 I think ideally we'd want to be able to specify different types of quantization like quantization_config = TorchAoConfig("int4_weight_only", group_size=128) (see https://huggingface.co/docs/transformers/main/en/quantization/torchao) so people can try out different quantization methods

I could be using

quant_config: Optional[QuantizationConfig] = None,
actually, but this requires updates to vllm, unless we copy paste the quantization config code here

@merrymercy

merrymercy commented Sep 8, 2024 •

Copy link
Copy Markdown
Collaborator

Feel free to copy over the code as we will gradually remove the dependency of vLLM (likely in one month or so)

@merrymercy merrymercy changed the title Add torchao quant to sgl llama model for testing Add torchao quant (int4/int8) to sgl llama model for testing Sep 9, 2024
@merrymercy merrymercy changed the title Add torchao quant (int4/int8) to sgl llama model for testing Add torchao quant (int4/int8/fp8) to llama models Sep 9, 2024
@merrymercy
merrymercy merged commit a7c47e0 into sgl-project:main Sep 9, 2024
@merrymercy

Copy link
Copy Markdown
Collaborator

@jerryzh168 Thanks for the contribution. It is merged.

I pushed some updates:

  • Move utils to python/sglang/srt/layers/torchao_utils.py
  • Added unit test test/srt/test_torchao.py

@merrymercy

merrymercy commented Sep 9, 2024 •

Copy link
Copy Markdown
Collaborator

I verified the performance on H100. Here are the results with a few comments:

  1. int4 decoding speed is pretty good. However, the prefill throughput seems much worse than the fp16 baseline. Do you have any ongoing efforts to improve it?
  2. int8 w/o torch.compile is very bad, but we cannot afford torch.compile for all batch sizes. Since fp8 is a much better alternative at the budget of 8-bit, we will likely only use fp8.
# fp16 baseline
# Decode.  median latency: 0.00728 s, median throughput:    137.41 token/s
python3 -m sglang.bench_latency --model meta-llama/Meta-Llama-3-8B --batch-size 1 --input 128 --output 8

# fp8 baseline
# Decode.  median latency: 0.00590 s, median throughput:    169.51 token/s
python3 -m sglang.bench_latency --model meta-llama/Meta-Llama-3-8B --batch-size 1 --input 128 --output 8 --quant fp8

# torchao int4
# Decode.  median latency: 0.00448 s, median throughput:    223.43 token/s
python3 -m sglang.bench_latency --model meta-llama/Meta-Llama-3-8B --batch-size 1 --input 128 --output 8 --torchao-config int4wo-128

# torchao int8 w/o compile
# Decode.  median latency: 0.02629 s, median throughput:     38.04 token/s
python3 -m sglang.bench_latency --model meta-llama/Meta-Llama-3-8B --batch-size 1 --input 128 --output 8 --torchao-config int8wo

I also got some errors with the current torchao release on Pypi when trying the following settings. Which version should I use?

  1. fp8 is not supported
python3 -m sglang.bench_latency --model meta-llama/Meta-Llama-3-8B --batch-size 1 --input 128 --output 8 --torchao-config fp8wo

[rank0]:   File "/root/sglang/python/sglang/srt/layers/torchao_utils.py", line 31, in torchao_quantize_param_data
[rank0]:     from torchao.quantization import float8_weight_only
[rank0]: ImportError: cannot import name 'float8_weight_only' from 'torchao.quantization' (/usr/local/lib/python3.10/dist-packages/torchao/quantization/__init__.py)
  1. torch.compile + torchao is not supported
python3 -m sglang.bench_latency --model meta-llama/Meta-Llama-3-8B --batch-size 1 --input 128 --output 8 --enable-torch-compile --torchao-config int4wo-128

[rank0]:   File "/usr/local/lib/python3.10/dist-packages/torchao/dtypes/affine_quantized_tensor.py", line 155, in dequantize
[rank0]:     int_data, scale, zero_point = self.layout_tensor.get_plain()
[rank0]: torch._dynamo.exc.InternalTorchDynamoError: 'FakeTensor' object has no attribute 'get_plain'

@jerryzh168

Copy link
Copy Markdown
Contributor Author

Thanks @merrymercy for the fixes, tests and merging the PR!

int4 decoding speed is pretty good. However, the prefill throughput seems much worse than the fp16 baseline. Do you have any ongoing efforts to improve it?

not yet I think, but we can take a look to understand why

int8 w/o torch.compile is very bad, but we cannot afford torch.compile for all batch sizes. Since fp8 is a much better alternative at the budget of 8-bit, we will likely only use fp8.

yeah int8 requires torch.compile to speedup, using fp8 sounds good to us as well.

fp8 is not supported

yeah currently we have torchao 0.4 in pypi, we are doing a new 0.5 release this week so fp8 should be supported this week

torch.compile + torchao is not supported

I've seen this before, this is because of some issue in pytorch dynamo/inductor code I think, and it should be fixed in pytorch nightly, maybe you can try installing pytorch nightly first to verify that the issue can be fix first. also do you have a version requirement for pytorch in sglang?

@zhyncs

zhyncs commented Sep 9, 2024

Copy link
Copy Markdown
Contributor

also do you have a version requirement for pytorch in sglang?

@jerryzh168 We use torch==2.4.0

@jerryzh168

Copy link
Copy Markdown
Contributor Author

I see, for 2.4.0 and below, we'd need to call https://github.com/pytorch/ao/blob/e1039abac7f429a8d7f489d047d9b34d6ac6afe2/torchao/utils.py#L269 for the model to be compilable I think, I'll try to verify as well when I got a chance today

@jerryzh168

Copy link
Copy Markdown
Contributor Author

for 2.4.0 there seems to be some issue even with work around, trying to debug now

@jerryzh168

Copy link
Copy Markdown
Contributor Author

@merrymercy @zhyncs

for the second issue "torch.compile + torchao is not supported" I can only repro in 2.4.0 and not sure how to fix, also the fix could just be needed in pytorch itself I think and we can't really back port the fix to 2.4.0. I'm wondering if it's OK for you to use torch nightly for now for testing? pytorch 2.5.0 is going to be released in one month.

@merrymercy merrymercy mentioned this pull request Sep 13, 2024
15 of 29 tasks
jerryzh168 added a commit to jerryzh168/sglang that referenced this pull request Sep 14, 2024
Summary:
Similar to sgl-project#1341 we add torchao quantization to mixtral model

Test Plan:
Note: compile is not working yet, and I can't install torchnightly locally and make it work either.
I'll wait for pytorch 2.5 release which happens in mid Oct, or check that again later

python3 -m sglang.bench_latency --model Qwen/Qwen1.5-MoE-A2.7B --batch-size 1 --input 128 --output 8

Warmup ...
Prefill. latency: 0.05532 s, throughput:   2313.73 token/s
Decode.  latency: 0.00896 s, throughput:    111.65 token/s
Decode.  latency: 0.00833 s, throughput:    120.04 token/s
Decode.  latency: 0.00869 s, throughput:    115.06 token/s
Decode.  latency: 0.00842 s, throughput:    118.79 token/s
Decode.  median latency: 0.00855 s, median throughput:    116.89 token/s
Total. latency:  0.090 s, throughput:   1471.26 token/s
Benchmark ...
Prefill. latency: 0.04294 s, throughput:   2980.61 token/s
Decode.  latency: 0.00839 s, throughput:    119.12 token/s
Decode.  latency: 0.00828 s, throughput:    120.78 token/s
Decode.  latency: 0.00857 s, throughput:    116.64 token/s
Decode.  latency: 0.00853 s, throughput:    117.19 token/s
Decode.  latency: 0.00859 s, throughput:    116.39 token/s
Decode.  median latency: 0.00853 s, median throughput:    117.17 token/s
Total. latency:  0.111 s, throughput:   1226.84 token/s

python3 -m sglang.bench_latency --model Qwen/Qwen1.5-MoE-A2.7B --batch-size 1 --input 128 --output 8 --torchao-config int4wo-128

Warmup ...
Prefill. latency: 0.06413 s, throughput:   1996.05 token/s
Decode.  latency: 0.00764 s, throughput:    130.84 token/s
Decode.  latency: 0.00748 s, throughput:    133.73 token/s
Decode.  latency: 0.00725 s, throughput:    137.84 token/s
Decode.  latency: 0.00721 s, throughput:    138.74 token/s
Decode.  median latency: 0.00737 s, median throughput:    135.76 token/s
Total. latency:  0.094 s, throughput:   1408.61 token/s
Benchmark ...
Prefill. latency: 0.05239 s, throughput:   2443.43 token/s
Decode.  latency: 0.00739 s, throughput:    135.25 token/s
Decode.  latency: 0.00720 s, throughput:    138.90 token/s
Decode.  latency: 0.00718 s, throughput:    139.21 token/s
Decode.  latency: 0.00722 s, throughput:    138.42 token/s
Decode.  latency: 0.00745 s, throughput:    134.30 token/s
Decode.  median latency: 0.00731 s, median throughput:    136.82 token/s
Total. latency:  0.111 s, throughput:   1223.51 token/s

A100, no compile
python3 -m sglang.bench_latency --model Qwen/Qwen1.5-MoE-A2.7B --batch-size 1 --input 128 --output 8 --torchao-config fp8wo
max_total_num_tokens=199454
Warmup ...
Prefill. latency: 0.06958 s, throughput:   1839.60 token/s
Decode.  latency: 0.02343 s, throughput:     42.68 token/s
Decode.  latency: 0.02342 s, throughput:     42.70 token/s
Decode.  latency: 0.02368 s, throughput:     42.23 token/s
Decode.  latency: 0.02337 s, throughput:     42.80 token/s
Decode.  median latency: 0.02342 s, median throughput:     42.69 token/s
Total. latency:  0.163 s, throughput:    807.48 token/s
Benchmark ...
Prefill. latency: 0.05767 s, throughput:   2219.36 token/s
Decode.  latency: 0.02293 s, throughput:     43.61 token/s
Decode.  latency: 0.02026 s, throughput:     49.36 token/s
Decode.  latency: 0.02029 s, throughput:     49.29 token/s
Decode.  latency: 0.02024 s, throughput:     49.41 token/s
Decode.  latency: 0.02026 s, throughput:     49.36 token/s
Decode.  median latency: 0.02025 s, median throughput:     49.39 token/s
Total. latency:  0.222 s, throughput:    611.87 token/s

Reviewers:

Subscribers:

Tasks:

Tags:
@zhyncs

zhyncs commented Sep 19, 2024

Copy link
Copy Markdown
Contributor

I'm wondering if it's OK for you to use torch nightly for now for testing?

@jerryzh168 I think we can give it a try, I will verify asap.

@zhyncs zhyncs added the quant LLM Quantization label Sep 19, 2024
@LIHUA919

Copy link
Copy Markdown

interesting

@zhyncs

zhyncs commented Nov 18, 2024

Copy link
Copy Markdown
Contributor

@jerryzh168 The main branch currently supports torch 2.5.1, and the installation method is as follows:

git clone -b main https://github.com/sgl-project/sglang.git
cd sglang

pip install --upgrade pip
pip install -e "python[all]"
# If you want to update torch 2.4 to torch 2.5.1 in an existing development environment, you can add `--force-reinstall`.
# pip install -e "python[all]" --force-reinstall

pip install flashinfer -i https://flashinfer.ai/whl/cu121/torch2.4/

If you have any questions, feel free to contact me anytime. Thanks!

timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 12, 2026
…t the instrument did not print

Review: /spinning/gpu-arb/weg2/REVIEW_COVERAGE_1348_0912.md against ef1b1a7.
Verdict there, and it was right: what the tool PRINTS is essentially true
(M1-M7 all die, the tally and SOURCE-DRIFT hold, OFF is byte-identical). The
defect is what it does NOT print -- and four of the reviewer's own mutants
survived all 21 tests.

MF-1 SILENCE INSTEAD OF REFUSAL -- the sgl-project#1329 shape itself.
The ingest iterated the dumps the glob FOUND, and `wlc.arm()` sat AFTER the
`bounce_lane_armed()` gate. A rank whose hook returned early -- which is what
`slots=True` did for three boots -- wrote no dump, and the report named it with
no word at all: group P's reading list read as the boot's. Fixed on both
sides. (a) The arm moved BEFORE the gate and leaves an immediate `legs=0` dump,
so a rank that ran no leg is a printable fact. (b) The launcher writes
`phase_coverage_EXPECT.json` (P=n,D=n,L=1) where the card count is first known,
and every expected-but-absent pair prints `reason=rank-wrote-no-dump`. Without
an expectation list the ingest REFUSES. The UNION line refuses over an
incomplete group instead of shrinking to `ranks=2` -- an intersection over a
subset of the ranks is a SUPERSET and named lines the absent rank executed.

MF-2 A STALE DUMP WAS READ AS THIS BOOT.
The dump directory is sgl-project#1292's and sgl-project#1292's is reused across boots; the blob
carried no boot identity, so yesterday's dump on an unchanged tree passed the
sha256 gate and printed. With MF-1 that composes into the worst output the
tool can make: the silence about a missing rank gets FILLED with a confident
wrong answer. Boot token (`tag:epoch:pid`, memoised on the namespace so P and D
carry the same one) in the blob and the manifest; a mismatched dump is refused
BY NAME and does not count as that rank having reported.

MF-3 `sha256: ""` SILENTLY DISABLED THE SOURCE GUARD.
`if dump_sha and dump_sha != tree_sha` -- an empty hash is falsy. The arm wrote
one on any OSError. Both halves fixed: the arm no longer swallows the error,
and the ingest treats an empty hash as `reason=no-source-hash` and prints no
reading list against an unverified source. This strand's tree moves between
boot and ingest routinely; that guard is the only thing holding.

MF-4 THE TRACER RAN TO PROCESS EXIT, AND THE COST WAS NOT ALLOWLIST-BOUNDED.
The build's own docstring said 2.60x "because the allowlist is eleven files and
not the tree". That is the instrument-text-lies class: the allowlist bounds
what is RECORDED, not what is PAID -- the trace callback fires for every Python
call in the process. Review measured NON-allowlisted code at 4.04x and full
tracing at 9.89x, and `note_teardown` deliberately did not stop. So every
ms/round, prefill, decode and flip figure of an armed boot was confounded, and
the wall-clock ring deadlines (`ring_guard.py` 2.0 s / 20.0 s, the W51 trend
test) were being eaten. The tracer now runs ONLY inside the leg bracket
(`begin_leg` before `run_leg_hook`, stop in `note_leg_end`, stop at teardown);
coverage.py accumulates across start/stop cycles (verified: leg 2 is a superset
of leg 1). `traced_ms` reports the window, `timings=CONFOUNDED` is on every
DUMP line and on a new launcher `WEG2-COVERAGE ARMED` line. W51 interaction is
recorded in the acceptance line as PLAUSIBLE, not measured.

ALSO TAKEN (review SHOULD/NOTE): artefact_n=/artefact_lines= per module, naming
the 23.7 % of lines that ran before the tracer went in rather than mixing them
into the wall list (S-1); allowlist split by process role, RANK_MODULES 10 /
LAUNCHER_MODULES 1, removing ~16 meaningless W90 per boot (S-2); the collision
guard made two-sided (`seam_coverage.lane_coverage_armed()`) plus a PRE-SPAWN
launcher refusal -- the per-rank refusal cost the whole window (S-3);
`dead`/`dead_where` in the blob and `_mark_dead` now flushes (S-4);
`threads_at_arm` declared, since threads predating the arm are never traced
(S-5); the docstring's "all three numbers are printed" corrected to two, and
`save_per_leg_ms` computed (S-6); launcher arm moved behind `--teardown` (N-6);
a missing EXPECTED rank now escalates the exit code without `--strict`, so a
caller reading only `$?` cannot read green over a boot that observed nothing
(N-1).

TEST HONESTY. The three substring wiring tests are DELETED and replaced by AST
and behaviour pins: a commented-out call contains the token, which is why
mutant MR4 unwired the instrument with every test green (sgl-project#1341 class).
`build_env` is now CALLED rather than grepped.

TWO FINDINGS OF MY OWN, both recorded rather than smoothed over:
1. THE MUTANT HARNESS LIED, in the direction its own header warns about. The
   round-2 block was generated by a script that turned `\n` inside the
   replacement patterns into real newlines; every embedded snippet was a
   SyntaxError, every mutation a silent no-op, and the harness reported EIGHT
   survivors against code that kills all eight. Same defect class as the
   subject: it could not tell "the mutant survived" from "the mutation never
   applied". `patch()` now hashes the file before and after and prints
   `!! MUTATION-NOOP ... Any GREEN below is the HARNESS, not the code`. Two
   stale round-1 entries fell out of the same check: M5's pattern had gone
   stale against the MF-3 split, and M7 pointed at a class deleted in round 2
   (a missing pytest node errors, i.e. reads RED for the wrong reason).
2. THE LEG BRACKET MADE `launcher.py` UNMEASURABLE, found by the execution
   smoke and not by a test: the launcher process never calls `begin_leg`, so
   the ingest reported `no-lines-recorded` about the file the process had just
   executed. `arm_launcher` now opens the bracket itself. This is the ONE place
   a process-lifetime tracer is right, because MF-4's hazard does not exist
   there: the launcher supervises, it does not serve.

EVIDENCE
Red-first round 2: 19 failed / 23 passed of 42, then 44/44 green.
Mutants 16/16 dead, 0 survivors, 0 no-ops (M1-M7 + MR2-MR9). MR1 is recorded in
the harness as a PROVEN EQUIVALENT mutant, not dropped: the reviewer's gap is
closed, but not by the line MR1 deletes -- measured on an empty directory with
`--expect P=2,D=1`, three `rank-wrote-no-dump` lines and a non-zero exit appear
with or without it. MR9 attacks the guarantee MR1 was reaching for.
Gate pair, both arms on this box, two worktrees. The xdist arm was NOT clean
and is reported as such: run A ONLY-NEW=1/GONE=10, run B (identical file set
via --ignore) ONLY-NEW=4/GONE=10 -- with DIFFERENT names, which is the tell.
Three lines against "my change": the NEW set is unstable across two candidate
runs; all 14 named tests pass SOLO on BOTH trees; and the deterministic arm --
`mem_cache` serial, no xdist, both trees, which is where all 14 names live --
is byte-identical: baseline 28 failures / 28 names, candidate 28 / 28,
ONLY-NEW=0 GONE=0. Mechanism: `-n 6 --dist loadfile` assigns files to workers
as they free up, so timing changes the packing; the candidate carries one extra
subtest (test_weg2_s0_unweave_1233 counts modules under srt/weg2/), and
mem_cache has order-dependent tests. That is a finding about the SUITE (a
candidate for sgl-project#1343's partition table), not about this change.
Execution smoke, real product path: `launcher --dry-run --xchg-coverage-diff`
wrote the manifest and the L dump; the ingest printed six
`rank-wrote-no-dump` lines (a dry run starts no ranks) and exited 1, verbatim:
  WEG2-COVERAGE NO-OBSERVATION module=<all> rank=0 group=D reason=rank-wrote-no-dump expected_by=boot-manifest modules=10 refusal=W90 Weg2CoverageNoObservation
ruff clean, codespell clean.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 12, 2026
…t the instrument did not print

Review: /spinning/gpu-arb/weg2/REVIEW_COVERAGE_1348_0912.md against ef1b1a7.
Verdict there, and it was right: what the tool PRINTS is essentially true
(M1-M7 all die, the tally and SOURCE-DRIFT hold, OFF is byte-identical). The
defect is what it does NOT print -- and four of the reviewer's own mutants
survived all 21 tests.

MF-1 SILENCE INSTEAD OF REFUSAL -- the sgl-project#1329 shape itself.
The ingest iterated the dumps the glob FOUND, and `wlc.arm()` sat AFTER the
`bounce_lane_armed()` gate. A rank whose hook returned early -- which is what
`slots=True` did for three boots -- wrote no dump, and the report named it with
no word at all: group P's reading list read as the boot's. Fixed on both
sides. (a) The arm moved BEFORE the gate and leaves an immediate `legs=0` dump,
so a rank that ran no leg is a printable fact. (b) The launcher writes
`phase_coverage_EXPECT.json` (P=n,D=n,L=1) where the card count is first known,
and every expected-but-absent pair prints `reason=rank-wrote-no-dump`. Without
an expectation list the ingest REFUSES. The UNION line refuses over an
incomplete group instead of shrinking to `ranks=2` -- an intersection over a
subset of the ranks is a SUPERSET and named lines the absent rank executed.

MF-2 A STALE DUMP WAS READ AS THIS BOOT.
The dump directory is sgl-project#1292's and sgl-project#1292's is reused across boots; the blob
carried no boot identity, so yesterday's dump on an unchanged tree passed the
sha256 gate and printed. With MF-1 that composes into the worst output the
tool can make: the silence about a missing rank gets FILLED with a confident
wrong answer. Boot token (`tag:epoch:pid`, memoised on the namespace so P and D
carry the same one) in the blob and the manifest; a mismatched dump is refused
BY NAME and does not count as that rank having reported.

MF-3 `sha256: ""` SILENTLY DISABLED THE SOURCE GUARD.
`if dump_sha and dump_sha != tree_sha` -- an empty hash is falsy. The arm wrote
one on any OSError. Both halves fixed: the arm no longer swallows the error,
and the ingest treats an empty hash as `reason=no-source-hash` and prints no
reading list against an unverified source. This strand's tree moves between
boot and ingest routinely; that guard is the only thing holding.

MF-4 THE TRACER RAN TO PROCESS EXIT, AND THE COST WAS NOT ALLOWLIST-BOUNDED.
The build's own docstring said 2.60x "because the allowlist is eleven files and
not the tree". That is the instrument-text-lies class: the allowlist bounds
what is RECORDED, not what is PAID -- the trace callback fires for every Python
call in the process. Review measured NON-allowlisted code at 4.04x and full
tracing at 9.89x, and `note_teardown` deliberately did not stop. So every
ms/round, prefill, decode and flip figure of an armed boot was confounded, and
the wall-clock ring deadlines (`ring_guard.py` 2.0 s / 20.0 s, the W51 trend
test) were being eaten. The tracer now runs ONLY inside the leg bracket
(`begin_leg` before `run_leg_hook`, stop in `note_leg_end`, stop at teardown);
coverage.py accumulates across start/stop cycles (verified: leg 2 is a superset
of leg 1). `traced_ms` reports the window, `timings=CONFOUNDED` is on every
DUMP line and on a new launcher `WEG2-COVERAGE ARMED` line. W51 interaction is
recorded in the acceptance line as PLAUSIBLE, not measured.

ALSO TAKEN (review SHOULD/NOTE): artefact_n=/artefact_lines= per module, naming
the 23.7 % of lines that ran before the tracer went in rather than mixing them
into the wall list (S-1); allowlist split by process role, RANK_MODULES 10 /
LAUNCHER_MODULES 1, removing ~16 meaningless W90 per boot (S-2); the collision
guard made two-sided (`seam_coverage.lane_coverage_armed()`) plus a PRE-SPAWN
launcher refusal -- the per-rank refusal cost the whole window (S-3);
`dead`/`dead_where` in the blob and `_mark_dead` now flushes (S-4);
`threads_at_arm` declared, since threads predating the arm are never traced
(S-5); the docstring's "all three numbers are printed" corrected to two, and
`save_per_leg_ms` computed (S-6); launcher arm moved behind `--teardown` (N-6);
a missing EXPECTED rank now escalates the exit code without `--strict`, so a
caller reading only `$?` cannot read green over a boot that observed nothing
(N-1).

TEST HONESTY. The three substring wiring tests are DELETED and replaced by AST
and behaviour pins: a commented-out call contains the token, which is why
mutant MR4 unwired the instrument with every test green (sgl-project#1341 class).
`build_env` is now CALLED rather than grepped.

TWO FINDINGS OF MY OWN, both recorded rather than smoothed over:
1. THE MUTANT HARNESS LIED, in the direction its own header warns about. The
   round-2 block was generated by a script that turned `\n` inside the
   replacement patterns into real newlines; every embedded snippet was a
   SyntaxError, every mutation a silent no-op, and the harness reported EIGHT
   survivors against code that kills all eight. Same defect class as the
   subject: it could not tell "the mutant survived" from "the mutation never
   applied". `patch()` now hashes the file before and after and prints
   `!! MUTATION-NOOP ... Any GREEN below is the HARNESS, not the code`. Two
   stale round-1 entries fell out of the same check: M5's pattern had gone
   stale against the MF-3 split, and M7 pointed at a class deleted in round 2
   (a missing pytest node errors, i.e. reads RED for the wrong reason).
2. THE LEG BRACKET MADE `launcher.py` UNMEASURABLE, found by the execution
   smoke and not by a test: the launcher process never calls `begin_leg`, so
   the ingest reported `no-lines-recorded` about the file the process had just
   executed. `arm_launcher` now opens the bracket itself. This is the ONE place
   a process-lifetime tracer is right, because MF-4's hazard does not exist
   there: the launcher supervises, it does not serve.

EVIDENCE
Red-first round 2: 19 failed / 23 passed of 42, then 44/44 green.
Mutants 16/16 dead, 0 survivors, 0 no-ops (M1-M7 + MR2-MR9). MR1 is recorded in
the harness as a PROVEN EQUIVALENT mutant, not dropped: the reviewer's gap is
closed, but not by the line MR1 deletes -- measured on an empty directory with
`--expect P=2,D=1`, three `rank-wrote-no-dump` lines and a non-zero exit appear
with or without it. MR9 attacks the guarantee MR1 was reaching for.
Gate pair, both arms on this box, two worktrees. The xdist arm was NOT clean
and is reported as such: run A ONLY-NEW=1/GONE=10, run B (identical file set
via --ignore) ONLY-NEW=4/GONE=10 -- with DIFFERENT names, which is the tell.
Three lines against "my change": the NEW set is unstable across two candidate
runs; all 14 named tests pass SOLO on BOTH trees; and the deterministic arm --
`mem_cache` serial, no xdist, both trees, which is where all 14 names live --
is byte-identical: baseline 28 failures / 28 names, candidate 28 / 28,
ONLY-NEW=0 GONE=0. Mechanism: `-n 6 --dist loadfile` assigns files to workers
as they free up, so timing changes the packing; the candidate carries one extra
subtest (test_weg2_s0_unweave_1233 counts modules under srt/weg2/), and
mem_cache has order-dependent tests. That is a finding about the SUITE (a
candidate for sgl-project#1343's partition table), not about this change.
Execution smoke, real product path: `launcher --dry-run --xchg-coverage-diff`
wrote the manifest and the L dump; the ingest printed six
`rank-wrote-no-dump` lines (a dry run starts no ranks) and exited 1, verbatim:
  WEG2-COVERAGE NO-OBSERVATION module=<all> rank=0 group=D reason=rank-wrote-no-dump expected_by=boot-manifest modules=10 refusal=W90 Weg2CoverageNoObservation
ruff clean, codespell clean.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 14, 2026
…her than a second scanner

Prior-art gate first (per order): sgl-project#1328's own file
(test_weg2_xchg_refusal_reachability_1328.py) already answers "can
production reach this raise/verdict at all" via a name-based AST
reference graph (_Index/build_index/reachable), with an empty-allowlist
ratchet plus a frozen, classified UNWIRED_DEBT for the exceptions, and a
synthetic-tree plant-proof (TestTheRatchetCanFail) that RED/GREENs its
own failure mode. sgl-project#1306 (test_weg2_wcode_uniqueness_1263.py) answers a
different question (is one W-code used twice) and isn't the right host.
Extended sgl-project#1328's file rather than building a second walker.

THE NEW QUESTION sgl-project#1389 ASKS, different from sgl-project#1328's: does the code that
READS a producer's log-line marker run under the SAME precondition the
producer's own construction requires? Five real instances from one
night (2026-09-13/14):

1-3. W7/W10 (P and D) and W9: count_marker() gates in launcher.py read
   markers ('sgl-project#706 canonical KV page active', 'canonical GDN blob
   active', 'sgl-project#1233 HICACHE BIGRAM KEYS FORCED') that only
   managers/cache_controller.py's HiCacheController ever prints, built
   only inside mem_cache/registry.py:192's `if
   ctx.enable_hierarchical_cache:` -- the gates ran unconditionally.
   ALREADY FIXED (sgl-project#1386 follow-ups 2/3, commits 683ccc5/2ef1a0979d).
4. W45: launcher.py's carrier census reads 'sgl-project#915 PREFETCH LIMIT', whose
   producer (mem_cache/prefetch_budget.py's log_prefetch_limit) is a
   no-op whenever its caller passes no cache_controller. ALREADY FIXED
   (sgl-project#1386 follow-up 4, d6c3d19).
5. The W100 guard bound to _weg2_xchg_inject_from_peer, which runs zero
   times on the metal (the real call site is _weg2_xchg_bounce_leg) --
   DESK10's own test passed because it checks the same wrong function.
   UNFIXED, in files locked to DESK10 (weight_updater.py) -- reported as
   a finding, not fixed here.
6. A wait-loop entry-vs-condition race (P enters 03:19:28Z, the
   condition it waits for exists at 03:19:32Z) -- no expressible static
   form found.

THE MECHANISM (ThePresenceRatchet): for each registered (gate anchor,
guard names, producer anchor, producer guard names) tuple,
_guard_chain_by_line walks the file's AST once and maps every line to
the source text of every enclosing `if` test (presence, not polarity --
an `if X: skip / else: gate` shape records X for lines in EITHER
branch, since both fix shapes in the corpus are exactly that). Two
per-entry checks (gate side guarded, producer side guarded) plus a
DEBT_SIZE_ON_THE_LINE-style pinned corpus size (4) so a removed entry
cannot silently pass -- the corpus itself is the required "does the
scan find the known corpus" probe (sgl-project#1341/sgl-project#1306's own lesson: a scan
that finds nothing reads green).

Instances 5 and 6 are DECLARED BOUNDARIES (PRESENCE_RATCHET_BOUNDARIES),
not invented rules: sgl-project#1328's own RESOLUTION docstring already states the
honest bound this ratchet shares (name-based resolution can call an
unwired path wired, never the reverse; no ordering/timing semantics).
Instance 5 gets one structural fact this file CAN verify without
touching the locked source -- the exact AST call-site count and line of
the wrapper _weg2_xchg_inject_from_peer (1, at weight_updater.py:1045)
-- pinned so a future desk can diff DESK10's rewire against it.

Tests: ThePresenceRatchet (4 corpus checks + shape/naming pins),
TestThePresenceRatchetCanFail (synthetic plant-proof: unguarded shape
RED, guarded shape GREEN, ambiguous/absent anchors reported not
silently misread), TestTheBoundariesAreDeclaredNotInvented (boundary
entries carry real reasons; the W100 wrapper's call-site count is
pinned). 10 new tests, all green; full file 27/27 green (17 pre-existing
+ 10 new).

Manually verified both required danger-direction mutants: (1) removed
one entry from PRESENCE_GATES -- exactly
test_the_corpus_cannot_shrink_or_grow_silently goes red, the two
per-entry scans stay green over what remains (proving the corpus-size
pin, not the per-entry logic, is what catches a silent removal);
restored, diff empty. (2) reverted the REAL launcher.py's W7/W10 group P
guard to its historical, unconditional pre-fix shape -- the ratchet goes
red against the ACTUAL file, not just a synthetic one, naming the exact
entry; restored, diff empty (git diff confirmed clean before
re-committing).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

quant LLM Quantization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants