gramineproject / examples

Sample applications configs for Gramine
BSD 3-Clause "New" or "Revised" License
28 stars 22 forks source link

PyTorch example error #81

Closed asim29 closed 10 months ago

asim29 commented 11 months ago

Hi, I am trying to run the PyTorch example. However, I seem to be running into an issue with the template manifest file. Providing more details below:

Error:

root@xyz:~/examples/pytorch# make
gramine-manifest \
    -Dlog_level=error \
    -Darch_libdir=/lib/x86_64-linux-gnu \
    -Dentrypoint=/usr/bin/python3.8 \
    pytorch.manifest.template > pytorch.manifest
Traceback (most recent call last):
  File "/usr/local/bin/gramine-manifest", line 33, in <module>
    main() # pylint: disable=no-value-for-parameter
  File "/usr/lib/python3/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/bin/gramine-manifest", line 29, in main
    manifest = Manifest.from_template(template, define)
  File "/usr/local/lib/python3.8/dist-packages/graminelibos/manifest.py", line 142, in from_template
    return cls(_env.from_string(template).render(**(variables or {})))
  File "/usr/lib/python3/dist-packages/jinja2/asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3/dist-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 25, in <module>
jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'get_sys_path'
make: *** [Makefile:20: pytorch.manifest] Error 1

Environment I am running all the code in a Docker container. I built the Docker container by using code from the Intel Confidential Computing Zoo dockerfile, using part of their dockerfile that builds Gramine from source on top of a base Ubuntu image, and then installing PyTorch using the README in examples/pytorch. The docker file is copy-paste below:

FROM ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive
ENV INSTALL_PREFIX=/usr/local
ENV LD_LIBRARY_PATH=${INSTALL_PREFIX}/lib:${INSTALL_PREFIX}/lib/x86_64-linux-gnu:${LD_LIBRARY_PATH}
ENV PATH=${INSTALL_PREFIX}/bin:${LD_LIBRARY_PATH}:${PATH}
ENV LC_ALL=C.UTF-8 LANG=C.UTF-8

# Install initial dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
        wget \
        gnupg \
        ca-certificates \
        software-properties-common \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

RUN ["/bin/bash", "-c", "set -o pipefail && echo 'deb [trusted=yes arch=amd64] https://download.01.org/intel-sgx/sgx_repo/ubuntu focal main' | tee /etc/apt/sources.list.d/intel-sgx.list"]
RUN ["/bin/bash", "-c", "set -o pipefail && wget -qO - https://download.01.org/intel-sgx/sgx_repo/ubuntu/intel-sgx-deb.key | apt-key add -"]

RUN apt-get update && apt-get install -y --no-install-recommends \
        apt-utils \
        ca-certificates \
        build-essential \
        autoconf \
        libtool \
        python3-pip \
        python3-dev \
        git \
        zlib1g-dev \
        unzip \
    vim \
        jq \
        pkg-config \
        gawk bison python3-click python3-jinja2 golang ninja-build \
        libcurl4-openssl-dev libprotobuf-c-dev python3-protobuf protobuf-c-compiler protobuf-compiler\
        libgmp-dev libmpfr-dev libmpc-dev libisl-dev nasm \
# Install SGX PSW
        libsgx-pce-logic libsgx-ae-qve libsgx-quote-ex libsgx-quote-ex-dev libsgx-qe3-logic sgx-aesm-service \
# Install SGX DCAP
        libsgx-dcap-ql-dev libsgx-dcap-quote-verify-dev libsgx-dcap-default-qpl libsgx-dcap-default-qpl-dev \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

# Gramine
ENV HOMEDIR=/home
ENV GRAMINEDIR=${HOMEDIR}/gramine
ENV SGX_DCAP_VERSION=DCAP_1.11
ENV GRAMINE_VERSION=v1.3.1
ENV ISGX_DRIVER_PATH=${GRAMINEDIR}/driver
ENV WERROR=1
ENV SGX=1

RUN ln -s /usr/bin/python3 /usr/bin/python \
    && pip3 install --no-cache-dir --upgrade \
        'pip>=23.1.2' 'wheel>=0.38.0' 'toml>=0.10' 'meson>=0.55' 'cryptography>=41.0.1' 'pyelftools>=0.29' 'setuptools==44.1.1' \
        'numpy==1.23.5' 'keras_preprocessing>=1.1.2' 'pandas==1.5.2' 'scikit-learn==1.1.3' 'matplotlib>=3.7.1'

WORKDIR ${GRAMINEDIR}
RUN git clone https://github.com/gramineproject/gramine.git ${GRAMINEDIR} \
    && git checkout ${GRAMINE_VERSION}

WORKDIR ${ISGX_DRIVER_PATH}
RUN git clone https://github.com/intel/SGXDataCenterAttestationPrimitives.git ${ISGX_DRIVER_PATH} \
    && git checkout ${SGX_DCAP_VERSION}

WORKDIR ${GRAMINEDIR}
RUN LD_LIBRARY_PATH="" meson setup build/ --buildtype=debug -Dprefix=${INSTALL_PREFIX} -Ddirect=enabled -Dsgx=enabled -Ddcap=enabled -Dsgx_driver=dcap1.10 -Dsgx_driver_include_path=${ISGX_DRIVER_PATH}/driver/linux/include \
    && LD_LIBRARY_PATH="" ninja -C build/ \
    && LD_LIBRARY_PATH="" ninja -C build/ installA

RUN gramine-sgx-gen-private-key

# Install PyTorch
RUN apt-get update && apt-get install -y --no-install-recommends \
        libnss-mdns \
        libnss-myhostname

RUN pip3 install --user torchvision pillow

I'm not sure how to fix this issue, when I run the standard python3 pytorchexample.py command it works fine. But running make does not work.

dimakuv commented 11 months ago

ENV GRAMINE_VERSION=v1.3.1

The PyTorch example works with Gramine v1.5. Please see https://gramine.readthedocs.io/en/latest/tutorials/pytorch/index.html#prerequisites