Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change python invocation #1908

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions pkg/dockerfile/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ coverage.xml
.pytest_cache
.hypothesis
`
const PythonCmd = "CMD [\"python\", \"-B\", \"--check-hash-based-pycs\", \"never\", \"-m\", \"cog.server.http\"]"
const StripDebugSymbolsCommand = "find / -type f -name \"*python*.so\" -not -name \"*cpython*.so\" -exec strip -S {} \\;"
const CFlags = "ENV CFLAGS=\"-O3 -march=native -funroll-loops -fno-strict-aliasing -flto -mtune=native -S\""

Expand Down Expand Up @@ -183,7 +184,7 @@ func (g *Generator) GenerateModelBase() (string, error) {
initialSteps,
`WORKDIR /src`,
`EXPOSE 5000`,
`CMD ["python", "-m", "cog.server.http"]`,
PythonCmd,
}, "\n"), nil
}

Expand Down Expand Up @@ -235,7 +236,7 @@ func (g *Generator) GenerateModelBaseWithSeparateWeights(imageName string) (weig
base = append(base,
`WORKDIR /src`,
`EXPOSE 5000`,
`CMD ["python", "-m", "cog.server.http"]`,
PythonCmd,
`COPY . /src`,
)

Expand Down Expand Up @@ -300,7 +301,8 @@ func (g *Generator) preamble() string {
return `ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu:/usr/local/nvidia/lib64:/usr/local/nvidia/bin
ENV NVIDIA_DRIVER_CAPABILITIES=all`
ENV NVIDIA_DRIVER_CAPABILITIES=all
ENV PYTHONDONTWRITEBYTECODE=1`
}

func (g *Generator) installTini() string {
Expand Down
31 changes: 19 additions & 12 deletions pkg/dockerfile/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu:/usr/local/nvidia/lib64:/usr/local/nvidia/bin
ENV NVIDIA_DRIVER_CAPABILITIES=all
ENV PYTHONDONTWRITEBYTECODE=1
` + testTini() + `COPY --from=deps --link /dep /usr/local/lib/python3.12/site-packages
WORKDIR /src
EXPOSE 5000
CMD ["python", "-m", "cog.server.http"]
CMD ["python", "-B", "--check-hash-based-pycs", "never", "-m", "cog.server.http"]
COPY . /src`

require.Equal(t, expected, actual)
Expand Down Expand Up @@ -140,14 +141,15 @@ ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu:/usr/local/nvidia/lib64:/usr/local/nvidia/bin
ENV NVIDIA_DRIVER_CAPABILITIES=all
ENV PYTHONDONTWRITEBYTECODE=1
` + testTini() + testInstallPython("3.12") + "RUN rm -rf /usr/bin/python3 && ln -s `realpath \\`pyenv which python\\`` /usr/bin/python3 && chmod +x /usr/bin/python3" + `
RUN --mount=type=bind,from=deps,source=/dep,target=/dep \
cp -rf /dep/* $(pyenv prefix)/lib/python*/site-packages; \
cp -rf /dep/bin/* $(pyenv prefix)/bin; \
pyenv rehash
WORKDIR /src
EXPOSE 5000
CMD ["python", "-m", "cog.server.http"]
CMD ["python", "-B", "--check-hash-based-pycs", "never", "-m", "cog.server.http"]
COPY . /src`

require.Equal(t, expected, actual)
Expand Down Expand Up @@ -190,12 +192,13 @@ ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu:/usr/local/nvidia/lib64:/usr/local/nvidia/bin
ENV NVIDIA_DRIVER_CAPABILITIES=all
ENV PYTHONDONTWRITEBYTECODE=1
` + testTini() + `RUN --mount=type=cache,target=/var/cache/apt,sharing=locked apt-get update -qq && apt-get install -qqy ffmpeg cowsay && rm -rf /var/lib/apt/lists/*
COPY --from=deps --link /dep /usr/local/lib/python3.12/site-packages
RUN cowsay moo
WORKDIR /src
EXPOSE 5000
CMD ["python", "-m", "cog.server.http"]
CMD ["python", "-B", "--check-hash-based-pycs", "never", "-m", "cog.server.http"]
COPY . /src`
require.Equal(t, expected, actual)

Expand Down Expand Up @@ -244,6 +247,7 @@ ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu:/usr/local/nvidia/lib64:/usr/local/nvidia/bin
ENV NVIDIA_DRIVER_CAPABILITIES=all
ENV PYTHONDONTWRITEBYTECODE=1
` + testTini() +
testInstallPython("3.12") + "RUN rm -rf /usr/bin/python3 && ln -s `realpath \\`pyenv which python\\`` /usr/bin/python3 && chmod +x /usr/bin/python3" + `
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked apt-get update -qq && apt-get install -qqy ffmpeg cowsay && rm -rf /var/lib/apt/lists/*
Expand All @@ -254,7 +258,7 @@ RUN --mount=type=bind,from=deps,source=/dep,target=/dep \
RUN cowsay moo
WORKDIR /src
EXPOSE 5000
CMD ["python", "-m", "cog.server.http"]
CMD ["python", "-B", "--check-hash-based-pycs", "never", "-m", "cog.server.http"]
COPY . /src`

require.Equal(t, expected, actual)
Expand Down Expand Up @@ -294,12 +298,13 @@ ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu:/usr/local/nvidia/lib64:/usr/local/nvidia/bin
ENV NVIDIA_DRIVER_CAPABILITIES=all
ENV PYTHONDONTWRITEBYTECODE=1
` + testTini() + `RUN --mount=type=cache,target=/var/cache/apt,sharing=locked apt-get update -qq && apt-get install -qqy cowsay && rm -rf /var/lib/apt/lists/*
COPY --from=deps --link /dep /usr/local/lib/python3.12/site-packages
RUN cowsay moo
WORKDIR /src
EXPOSE 5000
CMD ["python", "-m", "cog.server.http"]
CMD ["python", "-B", "--check-hash-based-pycs", "never", "-m", "cog.server.http"]
COPY . /src`
require.Equal(t, expected, actual)

Expand Down Expand Up @@ -406,6 +411,7 @@ ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu:/usr/local/nvidia/lib64:/usr/local/nvidia/bin
ENV NVIDIA_DRIVER_CAPABILITIES=all
ENV PYTHONDONTWRITEBYTECODE=1
` + testTini() +
testInstallPython("3.12") + `RUN rm -rf /usr/bin/python3 && ln -s ` + "`realpath \\`pyenv which python\\`` /usr/bin/python3 && chmod +x /usr/bin/python3" + `
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked apt-get update -qq && apt-get install -qqy ffmpeg cowsay && rm -rf /var/lib/apt/lists/*
Expand All @@ -419,7 +425,7 @@ COPY --from=weights --link /src/models /src/models
COPY --from=weights --link /src/root-large /src/root-large
WORKDIR /src
EXPOSE 5000
CMD ["python", "-m", "cog.server.http"]
CMD ["python", "-B", "--check-hash-based-pycs", "never", "-m", "cog.server.http"]
COPY . /src`

require.Equal(t, expected, runnerDockerfile)
Expand Down Expand Up @@ -484,10 +490,11 @@ ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu:/usr/local/nvidia/lib64:/usr/local/nvidia/bin
ENV NVIDIA_DRIVER_CAPABILITIES=all
ENV PYTHONDONTWRITEBYTECODE=1
` + testTini() + `COPY --from=deps --link /dep /usr/local/lib/python3.12/site-packages
WORKDIR /src
EXPOSE 5000
CMD ["python", "-m", "cog.server.http"]
CMD ["python", "-B", "--check-hash-based-pycs", "never", "-m", "cog.server.http"]
COPY . /src`

require.Equal(t, expected, actual)
Expand Down Expand Up @@ -515,7 +522,7 @@ FROM r8.im/replicate/cog-test-weights AS weights
FROM r8.im/cog-base:python3.12
WORKDIR /src
EXPOSE 5000
CMD ["python", "-m", "cog.server.http"]
CMD ["python", "-B", "--check-hash-based-pycs", "never", "-m", "cog.server.http"]
COPY . /src`

require.Equal(t, expected, actual)
Expand Down Expand Up @@ -557,7 +564,7 @@ ENV CFLAGS=
RUN cowsay moo
WORKDIR /src
EXPOSE 5000
CMD ["python", "-m", "cog.server.http"]
CMD ["python", "-B", "--check-hash-based-pycs", "never", "-m", "cog.server.http"]
COPY . /src`
require.Equal(t, expected, actual)

Expand Down Expand Up @@ -612,7 +619,7 @@ ENV CFLAGS=
RUN cowsay moo
WORKDIR /src
EXPOSE 5000
CMD ["python", "-m", "cog.server.http"]
CMD ["python", "-B", "--check-hash-based-pycs", "never", "-m", "cog.server.http"]
COPY . /src`, expectedTorchVersion)

require.Equal(t, expected, actual)
Expand Down Expand Up @@ -664,7 +671,7 @@ ENV CFLAGS=
RUN cowsay moo
WORKDIR /src
EXPOSE 5000
CMD ["python", "-m", "cog.server.http"]
CMD ["python", "-B", "--check-hash-based-pycs", "never", "-m", "cog.server.http"]
COPY . /src`

require.Equal(t, expected, actual)
Expand Down Expand Up @@ -715,7 +722,7 @@ ENV CFLAGS=
RUN cowsay moo
WORKDIR /src
EXPOSE 5000
CMD ["python", "-m", "cog.server.http"]
CMD ["python", "-B", "--check-hash-based-pycs", "never", "-m", "cog.server.http"]
COPY . /src`

require.Equal(t, expected, actual)
Expand Down