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

Add mount caches to pip installs #1944

Merged
merged 1 commit into from
Sep 20, 2024
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
10 changes: 5 additions & 5 deletions pkg/dockerfile/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,13 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked apt-get update -qq &
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
` + fmt.Sprintf(`
RUN curl -s -S -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash && \
RUN --mount=type=cache,target=/root/.cache/pip curl -s -S -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash && \
git clone https://github.com/momo-lab/pyenv-install-latest.git "$(pyenv root)"/plugins/pyenv-install-latest && \
export PYTHON_CONFIGURE_OPTS='--enable-optimizations --with-lto' && \
export PYTHON_CFLAGS='-O3' && \
pyenv install-latest "%s" && \
pyenv global $(pyenv install-latest --print "%s") && \
pip install --no-cache-dir "wheel<1"`, py, py) + `
pip install "wheel<1"`, py, py) + `
RUN rm -rf /usr/bin/python3 && ln -s ` + "`realpath \\`pyenv which python\\`` /usr/bin/python3 && chmod +x /usr/bin/python3", nil
// for sitePackagesLocation, kind of need to determine which specific version latest is (3.8 -> 3.8.17 or 3.8.18)
// install-latest essentially does pyenv install --list | grep $py | tail -1
Expand All @@ -405,7 +405,7 @@ func (g *Generator) installCog() (string, error) {
if err != nil {
return "", err
}
pipInstallLine := fmt.Sprintf("RUN --mount=type=cache,target=/root/.cache/pip pip install --no-cache-dir -t /dep %s", containerPath)
pipInstallLine := fmt.Sprintf("RUN --mount=type=cache,target=/root/.cache/pip pip install -t /dep %s", containerPath)
if g.strip {
pipInstallLine += " && " + StripDebugSymbolsCommand
}
Expand Down Expand Up @@ -440,7 +440,7 @@ func (g *Generator) pipInstalls() (string, error) {
return "", err
}

pipInstallLine := "RUN pip install --no-cache-dir -r " + containerPath
pipInstallLine := "RUN --mount=type=cache,target=/root/.cache/pip pip install -r " + containerPath
if g.strip {
pipInstallLine += " && " + StripDebugSymbolsCommand
}
Expand Down Expand Up @@ -485,7 +485,7 @@ func (g *Generator) pipInstallStage() (string, error) {
fromLine = fromLine + "\nRUN " + buildStageDeps
}

pipInstallLine := "RUN --mount=type=cache,target=/root/.cache/pip pip install --no-cache-dir -t /dep -r " + containerPath
pipInstallLine := "RUN --mount=type=cache,target=/root/.cache/pip pip install -t /dep -r " + containerPath
if g.strip {
pipInstallLine += " && " + StripDebugSymbolsCommand
}
Expand Down
22 changes: 11 additions & 11 deletions pkg/dockerfile/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func testInstallCog(relativeTmpDir string) string {
wheel := getWheelName()
return fmt.Sprintf(`COPY %s/%s /tmp/%s
ENV CFLAGS="-O3 -funroll-loops -fno-strict-aliasing -flto -S"
RUN --mount=type=cache,target=/root/.cache/pip pip install --no-cache-dir -t /dep /tmp/%s
RUN --mount=type=cache,target=/root/.cache/pip pip install -t /dep /tmp/%s
ENV CFLAGS=`, relativeTmpDir, wheel, wheel, wheel)
}

Expand Down Expand Up @@ -72,13 +72,13 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked apt-get update -qq &
git \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
RUN curl -s -S -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash && \
RUN --mount=type=cache,target=/root/.cache/pip curl -s -S -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash && \
git clone https://github.com/momo-lab/pyenv-install-latest.git "$(pyenv root)"/plugins/pyenv-install-latest && \
export PYTHON_CONFIGURE_OPTS='--enable-optimizations --with-lto' && \
export PYTHON_CFLAGS='-O3' && \
pyenv install-latest "%s" && \
pyenv global $(pyenv install-latest --print "%s") && \
pip install --no-cache-dir "wheel<1"
pip install "wheel<1"
`, version, version)
}

Expand Down Expand Up @@ -185,7 +185,7 @@ FROM r8.im/replicate/cog-test-weights AS weights
` + testPipInstallStage(gen.relativeTmpDir) + `
COPY ` + gen.relativeTmpDir + `/requirements.txt /tmp/requirements.txt
ENV CFLAGS="-O3 -funroll-loops -fno-strict-aliasing -flto -S"
RUN --mount=type=cache,target=/root/.cache/pip pip install --no-cache-dir -t /dep -r /tmp/requirements.txt
RUN --mount=type=cache,target=/root/.cache/pip pip install -t /dep -r /tmp/requirements.txt
ENV CFLAGS=
FROM python:3.12-slim
ENV DEBIAN_FRONTEND=noninteractive
Expand Down Expand Up @@ -240,7 +240,7 @@ FROM r8.im/replicate/cog-test-weights AS weights
` + testPipInstallStage(gen.relativeTmpDir) + `
COPY ` + gen.relativeTmpDir + `/requirements.txt /tmp/requirements.txt
ENV CFLAGS="-O3 -funroll-loops -fno-strict-aliasing -flto -S"
RUN --mount=type=cache,target=/root/.cache/pip pip install --no-cache-dir -t /dep -r /tmp/requirements.txt
RUN --mount=type=cache,target=/root/.cache/pip pip install -t /dep -r /tmp/requirements.txt
ENV CFLAGS=
FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04
ENV DEBIAN_FRONTEND=noninteractive
Expand Down Expand Up @@ -327,7 +327,7 @@ build:
_, actual, _, err := gen.GenerateModelBaseWithSeparateWeights("r8.im/replicate/cog-test")
require.NoError(t, err)
fmt.Println(actual)
require.Contains(t, actual, `pip install --no-cache-dir -t /dep -r /tmp/requirements.txt`)
require.Contains(t, actual, `pip install -t /dep -r /tmp/requirements.txt`)
}

// mockFileInfo is a test type to mock os.FileInfo
Expand Down Expand Up @@ -404,7 +404,7 @@ FROM r8.im/replicate/cog-test-weights AS weights
` + testPipInstallStage(gen.relativeTmpDir) + `
COPY ` + gen.relativeTmpDir + `/requirements.txt /tmp/requirements.txt
ENV CFLAGS="-O3 -funroll-loops -fno-strict-aliasing -flto -S"
RUN --mount=type=cache,target=/root/.cache/pip pip install --no-cache-dir -t /dep -r /tmp/requirements.txt
RUN --mount=type=cache,target=/root/.cache/pip pip install -t /dep -r /tmp/requirements.txt
ENV CFLAGS=
FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04
ENV DEBIAN_FRONTEND=noninteractive
Expand Down Expand Up @@ -559,7 +559,7 @@ FROM r8.im/cog-base:python3.12
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 ` + gen.relativeTmpDir + `/requirements.txt /tmp/requirements.txt
ENV CFLAGS="-O3 -funroll-loops -fno-strict-aliasing -flto -S"
RUN pip install --no-cache-dir -r /tmp/requirements.txt
RUN --mount=type=cache,target=/root/.cache/pip pip install -r /tmp/requirements.txt
ENV CFLAGS=
RUN cowsay moo
WORKDIR /src
Expand Down Expand Up @@ -614,7 +614,7 @@ FROM r8.im/cog-base:cuda11.8-python3.11-torch%s
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 `+gen.relativeTmpDir+`/requirements.txt /tmp/requirements.txt
ENV CFLAGS="-O3 -funroll-loops -fno-strict-aliasing -flto -S"
RUN pip install --no-cache-dir -r /tmp/requirements.txt
RUN --mount=type=cache,target=/root/.cache/pip pip install -r /tmp/requirements.txt
ENV CFLAGS=
RUN cowsay moo
WORKDIR /src
Expand Down Expand Up @@ -666,7 +666,7 @@ FROM r8.im/cog-base:cuda11.8-python3.12-torch2.3.1
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 ` + gen.relativeTmpDir + `/requirements.txt /tmp/requirements.txt
ENV CFLAGS="-O3 -funroll-loops -fno-strict-aliasing -flto -S"
RUN pip install --no-cache-dir -r /tmp/requirements.txt
RUN --mount=type=cache,target=/root/.cache/pip pip install -r /tmp/requirements.txt
ENV CFLAGS=
RUN cowsay moo
WORKDIR /src
Expand Down Expand Up @@ -717,7 +717,7 @@ FROM r8.im/cog-base:cuda11.8-python3.12-torch2.3.1
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 ` + gen.relativeTmpDir + `/requirements.txt /tmp/requirements.txt
ENV CFLAGS="-O3 -funroll-loops -fno-strict-aliasing -flto -S"
RUN pip install --no-cache-dir -r /tmp/requirements.txt && find / -type f -name "*python*.so" -not -name "*cpython*.so" -exec strip -S {} \;
RUN --mount=type=cache,target=/root/.cache/pip pip install -r /tmp/requirements.txt && find / -type f -name "*python*.so" -not -name "*cpython*.so" -exec strip -S {} \;
ENV CFLAGS=
RUN cowsay moo
WORKDIR /src
Expand Down