Skip to content

misc: create slim srt image tag - #999

Closed
vhain wants to merge 2 commits into
sgl-project:mainfrom
tmfi-us:ryan/docker/slim-srt-image
Closed

vhain wants to merge 2 commits into
sgl-project:mainfrom
tmfi-us:ryan/docker/slim-srt-image

Conversation

@vhain

@vhain vhain commented Aug 9, 2024

Copy link
Copy Markdown
Contributor

Thank you for your contribution, we really appreciate it. The following instructions will help improve your pull request and make it easier to receive feedback. If there are any items you don't understand, don't worry. Just submit the pull request and ask the maintainers for help.

Motivation

The current lmsysorg/sglang image is somewhat painful to download in some shared cloud environment, where they don't cache images locally, due to it's size (compressed size of 8.19 GB). Uncompressed image size:

$ docker inspect -f "{{ .Size }}" lmsysorg/sglang:latest | numfmt --to=si
16G

Modification

  • This PR defines standalone docker build stage srt which only installs sglang[srt] on top of python:slim image. If anyone think we need to use nvidia/cuda:*-base-* image, I can change this PR to use that image instead. The result is whopping -46% in size (compressed size of 4.44 GB). Uncompressed image size:
    $ docker inspect -f "{{ .Size }}" tmfi/sglang:latest-srt | numfmt --to=si
    8.6G
    • Turned out that we don't need full nvidia/cuda:*-devel-* image to run srt (seems like all the needed CUDA stuffs are already being installed by pip and/or mounted by the host machine).
    • So the srt build stage is basically simply gonna build the wheel from the base stage, and installing it.
    • I have rolled out this srt-only image to some of our production instances and are working fine.
  • In order to not affect any other environments and/or use cases, I've created a new tag by appending -srt to the existing tags, so that the existing tags can still be used as-is.
  • The new -srt tagged images will have python -m sglang.launch_server as an ENTRYPOINT.

Discussions

  • The current base image is installing Python 3.8. However 3.8's EOL is approaching (it's just 2 months away from now), so we might want to upgrade it? (cc: @Ying1123)
  • I can see that the base Dockerfile clones from Github, while it the Github workflow is already checking out the full repo. This can lead into race-condition and potentially mismatching version (Git tag != Docker image tag). We can change this to use COPY instruction instead? (cc: @zhyncs)

Checklist

  • 1. Ensure pre-commit pre-commit run --all-files or other linting tools are used to fix potential lint issues.
  • 2. Confirm that modifications are covered by complete unit tests. If not, please add more unit tests for correctness.
  • 3. Modify documentation as needed, such as docstrings or example tutorials.

@zhyncs

zhyncs commented Aug 9, 2024

Copy link
Copy Markdown
Contributor

Very interesting changes, looks good, I'll come back and check it out later. Thanks.

Comment thread README.md Resolved

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

Looks good!

Comment thread docker/Dockerfile
# build the wheel
FROM base AS build

RUN --mount=type=cache,target=/root/.cache/pip \

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.

I don't recommend using absolute paths. What's the purpose of adding them here?

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.

It is inspired from vllm's Dockerfile:
https://github.com/vllm-project/vllm/blob/main/Dockerfile#L47

RUN --mount=type=cache,target=/root/.cache/pip \
    python3 -m pip install -r requirements-cuda.txt

https://docs.docker.com/build/guide/mounts/#add-a-cache-mount
The default pip cache directory (as the docker build is running as root), is /root/.cache/pip.

The --mount in Dockerfile will mount the file (or volume) only during the RUN operation, and that will not preserved in the produced image.

This is kinda equivalent as:

  • Run pip install with wheels cached to local machines (to deduplicate subsequent downloads in the future)
  • Then remove the cache from the docker image layer.

@Ying1123

Ying1123 commented Aug 9, 2024

Copy link
Copy Markdown
Contributor

Yes, it's a good idea to upgrade the python version. Thanks!

Comment thread docker/Dockerfile
RUN python3 -m build

# minimal sglang srt image
FROM python:3.10-slim AS srt

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.

Use configuration for version instead of hardcoding.

Comment thread docker/Dockerfile
RUN --mount=type=bind,from=build,src=/sgl-workspace/sglang/python/dist,target=/sgl-workspace/dist \
--mount=type=cache,target=/root/.cache/pip \
pip install --verbose $(find /sgl-workspace/dist -name "*.whl" -printf "%p[srt] ") && \
pip install --index https://flashinfer.ai/whl/cu121/torch2.4/ flashinfer

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.

same as above

Comment thread docker/Dockerfile
pip install --verbose $(find /sgl-workspace/dist -name "*.whl" -printf "%p[srt] ") && \
pip install --index https://flashinfer.ai/whl/cu121/torch2.4/ flashinfer

ENTRYPOINT [ "python3", "-m", "sglang.launch_server" ]

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.

Why add ENTRYPOINT here?

@zhyncs zhyncs mentioned this pull request Aug 11, 2024
3 of 4 tasks
@zhyncs

zhyncs commented Aug 11, 2024

Copy link
Copy Markdown
Contributor

Hi @vhain Thanks for your contribution. I raise another PR and co author with you ref #1033 I'll close this for now. Thanks!

@zhyncs zhyncs closed this Aug 11, 2024
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 29, 2026
`mb_id` and `forward_ct` were both checked and both correct -- and both too
coarse. A chunked request occupies the SAME mb slot across SEVERAL passes,
and one forward of offset IS the normal pipeline state. Measured on this
config in boot 45: one request walked `len_input` 4096 -> 4096 -> 254 over
three passes, identical on all three ranks, with the extend invariant holding
at every point. Both identities stayed valid across a factor-16 change in the
quantity the guard compares.

An identity check is only as good as the match between its GRANULARITY and
what varies. Two passed identity checks are not proof of the same work.

So the stamp now carries the sender's CHUNK POSITION -- the rid and
`extend_range` of the batch the proxy was built from -- and the receiver
attaches its own through the same helper, so the guard prints like against
like. Equal means one pass and the divergence is elsewhere; different means
the guard is comparing two passes of the same request, which is what the
measured walk predicts and what the unstable sign requires (sender larger in
boot 44 at 422/254, smaller in boots 26-34 at 253/254/277 against 301/302 --
which pair collides decides the sign).

Coverage is satisfied by construction here, and that is why the field sits at
the guard rather than in the sgl-project#998 probe: the guard only prints when it fires,
so the reading is the dying request by definition. Two closing statements of
this window rested on samples that excluded it.

Appended at index 5; every stamp consumer indexes positionally behind a
`>= N` guard, verified again by reading epoch out of a 6-tuple. The helper
returns (-1,-1,-1) rather than raising -- a stamp may not break a send.

THE GUARD IS NOT TO BE REMOVED. If it turns out to be comparing two passes,
it is the only thing making that confusion visible today; the answer is a
stamp that lets it be RIGHT, not switching it off.

Evidence: desk. py_compile on both files; the helper degrades to its sentinel
on an empty scheduler, and `pp_proxy_stamp_epoch` still reads index 3 from a
6-tuple. Belegstufe: DESK-BEWIESEN.
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.

4 participants