ARG VERSION=mmcv1.6_dtk26.04_v1.0_HygonBW1101
FROM aicompute.tencentcloudcr.com/hyperdrive/hygon:${VERSION}

ARG COS_BASE_URL="https://haihub-model-1251001002.cos.ap-shanghai.myqcloud.com/HyperDrive/haiguang/hygon-bench/train"

SHELL ["/bin/bash", "-c"]

# Download Hyhal for compile
RUN aria2c --enable-color=false --show-console-readout=false -x 8 -s 8 -k 1M -d /tmp -o hyhal.tar.gz ${COS_BASE_URL}/common/hyhal.tar.gz && \
    mkdir -p /opt/hyhal && \
    tar -zxf /tmp/hyhal.tar.gz --strip-components=2 -C /opt/hyhal && \
    rm -rf /tmp/hyhal.tar.gz

COPY PointPillars/mmdetection3d /workspace/PointPillars

# Replace mmcv==1.6 with mmcv==2.2
RUN pip uninstall -y mmcv-full && \
    pip install https://haihub-model-1251001002.cos.ap-shanghai.myqcloud.com/HyperDrive/haiguang/hygon-bench/train/autodrive/mmcv-2.2.0%2Bdas.opt1.dtk2604.20260204.gb9d4e636-cp310-cp310-manylinux_2_28_x86_64.whl && \
    pip install mmengine==0.10.7 && pip install mmdet==3.3.0 && sed 's/2.2.0/2.2.1/' -i /usr/local/lib/python3.10/dist-packages/mmdet/__init__.py 

RUN mv /usr/local/lib/python3.10/dist-packages/mmengine/runner/runner.py /usr/local/lib/python3.10/dist-packages/mmengine/runner/runner.py.bak && \
    wget https://taco-public-1251001002.cos.ap-shanghai.myqcloud.com/external/haiguang/whl/runner.py -P /usr/local/lib/python3.10/dist-packages/mmengine/runner/
    # bash install_deps.sh && \
RUN cd /workspace/PointPillars && \
    source /root/.bashrc && \
    pip install --ignore-installed blinker && \
    pip install -r requirements/runtime.txt && \
    source /root/.bashrc && \
    source /usr/local/bin/fastpt -C && \
    cd /workspace/PointPillars && \
    pip uninstall -y mmdet3d && \
    FORCE_CUDA=1 python setup.py develop && \
    source /usr/local/bin/fastpt -E || true # 编译成功也会返回1，忽略错误 @hygon

# 兼容 THPC 老模板
COPY build.sh /opt/build_pointpillars.sh

COPY one_step_data.sh /workspace/PointPillars/HyperDrive/tools/one_step_data.sh
COPY start_mmdet3d.sh /workspace/PointPillars/tools/start_mmdet3d.sh
COPY pointpillars_hv_fpn_sbn-all_8xb4-2x_nus-3d_perf_test.py /workspace/PointPillars/configs/pointpillars/
COPY schedule-2x_perf_test.py /workspace/PointPillars/configs/_base_/schedules/

RUN rm -f /root/.bash_history

# Remove hyhal for runtime
RUN rm -rf /opt/hyhal

WORKDIR /workspace/PointPillars
