[tab] build_conda.sh (shellscript)
#!/bin/bash

# set -ex

# create conda
# yes '' | "${SHELL}" <(curl -L micro.mamba.pm/install.sh)
# Explicitly initialize micromamba for non-interactive shells
source ~/.bashrc

# Clean up corrupted environment and recreate
micromamba create -n miles python=3.12 pip -c conda-forge -y

micromamba activate miles
export CUDA_HOME="$CONDA_PREFIX"

export BASE_DIR=${BASE_DIR:-"/fast/project/HFMI_SynergyUnit/mihir/"}
cd $BASE_DIR

# install cuda 12.9 as it's the default cuda version for torch
micromamba install -n miles cuda cuda-nvtx cuda-nvtx-dev nccl -c nvidia/label/cuda-12.9.1 -y
micromamba install -n miles -c conda-forge cudnn -y

# prevent installing cuda 13.0 for sglang
pip install cuda-python==12.9.1
pip install torch==2.8.0 torchvision==0.23.0 torchaudio==2.8.0 --index-url https://download.pytorch.org/whl/cu129

# install sglang
# git clone https://github.com/sgl-project/sglang.git
cd sglang
git checkout 303cc957e62384044dfa8e52d7d8af8abe12f0ac
# Install the python packages
pip install -e "python[all]"


pip install cmake ninja



cd $BASE_DIR
# git clone https://github.com/Dao-AILab/flash-attention.git
cd flash-attention/hopper
python setup.py install
echo "DONE FOR NOW"

# flash attn
# the newest version megatron supports is v2.7.4.post1
# MAX_JOBS=64 pip -v install flash-attn==2.7.4.post1 --no-build-isolation
# pip install https://github.com/mjun0812/flash-attention-prebuild-wheels/releases/download/v0.3.18/flash_attn-2.7.4%2Bcu128torch2.8-cp312-cp312-linux_x86_64.whl

# pip install git+https://github.com/ISEEKYAN/mbridge.git@89eb10887887bc74853f89a4de258c0702932a1c --no-deps
# pip install --no-build-isolation "transformer_engine[pytorch]==2.8.0" --no-cache-dir
# pip install flash-linear-attention==0.4.0
# NVCC_APPEND_FLAGS="--threads 4" \
  # pip -v install --disable-pip-version-check --no-cache-dir \
  # --no-build-isolation \
  # --config-settings "--build-option=--cpp_ext --cuda_ext --parallel 8" git+https://github.com/NVIDIA/apex.git@10417aceddd7d5d05d7cbf7b0fc2daad1105f8b4

# git clone https://github.com/NVIDIA/Megatron-LM.git --recursive && \
    # cd Megatron-LM && git checkout ${MEGATRON_COMMIT} && \
    # pip install -e .

# pip install git+https://github.com/fzyzcjy/torch_memory_saver.git@9b8b788fdeb9c2ee528183214cef65a99b71e7d5 --no-cache-dir --force-reinstall
# pip install git+https://github.com/fzyzcjy/Megatron-Bridge.git@dev_rl --no-build-isolation
# pip install nvidia-modelopt[torch]>=0.37.0 --no-build-isolation

# megatron
# cd $BASE_DIR
# git clone https://github.com/NVIDIA/Megatron-LM.git --recursive && \
  # cd Megatron-LM/ && git checkout core_v0.14.0 && \
  # pip install -e .

# install miles and apply patches

# if miles does not exist locally, clone it
# if [ ! -d "$BASE_DIR/miles" ]; then
  # cd $BASE_DIR
  # git clone  https://github.com/radixark/miles.git
  # cd miles/
  # export MILES_DIR=$BASE_DIR/miles
  # pip install -e .
# else
  # export MILES_DIR=$BASE_DIR/
  # pip install -e .
# fi

# apply patch
# cd $BASE_DIR/sglang
# git apply $MILES_DIR/docker/patch/v0.5.5.post1/sglang.patch
# cd $BASE_DIR/Megatron-LM
# git apply $MILES_DIR/docker/patch/v0.5.5.post1/megatron.patch