File size: 4,233 Bytes
e8d350a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# MMSciCode env reconstruction on the domestic server

This bundle reconstructs the 204 MMSciCode conda envs on a domestic Chinese
server using mirror sources (no need to download the 165 GB tarball repo).
It then packs each env into a tarball and builds a Docker image per env.

## Inputs (from HF: `MMSciCode/mmsci-envs-tmp`)

```
configs/
  <env>/
    env.yml           # conda env create -f
    explicit.txt      # conda list --explicit --md5 (URL-pinned fallback)
    pip-freeze.txt    # raw pip freeze from local env
    pip-clean.txt     # pip-freeze with conda-built file:// stripped
    editable.txt      # tab-separated: <egg-link name> \t <original source path>
    meta.json         # python ver, has_cuda hint, editable_count
editable_bundle.tar.gz  # only present if any env had editable installs
```

## Domestic-server prerequisites

- conda (or miniconda) installed; conda >= 22.x
- `mamba` from the base env: `conda install -n base -c conda-forge mamba conda-pack`
- Docker (with `nvidia-docker` runtime if envs need GPU)
- ~200 GB free disk for staging tarballs + ~300 GB for Docker images

## Step 1 β€” configure mirrors

```bash
cp configs_repo/remote/condarc.template ~/.condarc
mkdir -p ~/.config/pip
cp configs_repo/remote/pip.conf.template ~/.config/pip/pip.conf
```

## Step 2 β€” fetch the artifacts

```bash
# example using huggingface_hub with HF_ENDPOINT=https://hf-mirror.com if needed
huggingface-cli download MMSciCode/mmsci-envs-tmp \
    --repo-type dataset \
    --local-dir /home/mmsci/repo \
    --include 'configs/**' 'editable_bundle.tar.gz'

cd /home/mmsci/repo
[ -f editable_bundle.tar.gz ] && tar -xzf editable_bundle.tar.gz   # -> editable_sources/
```

## Step 3 β€” build all envs (parallel) and pack each as a tarball

```bash
CONFIGS_DIR=/home/mmsci/repo/configs \
OUT_DIR=/home/mmsci/conda_packs \
EDITABLE_SRC=/home/mmsci/repo/editable_sources \
MAMBA_BIN=/opt/conda/bin/mamba \
CONDA_PACK=/opt/conda/bin/conda-pack \
JOBS=4 \
bash /home/mmsci/configs_repo/remote/build_envs_remote.sh
```

Outputs:
- `$OUT_DIR/<env>.tar.gz` β€” per-env conda-pack tarball
- `$OUT_DIR/build.state.tsv` β€” per-env status (done/skip/fail)
- `$OUT_DIR/build.failed.txt` β€” failed envs (re-run script to retry; idempotent)
- `$OUT_DIR/_logs/<env>.log` β€” per-env mamba + pack log

Expect 5–15% of envs to fail on first pass (mirror gaps, conda-pack errors,
editable misses). Inspect the failed logs and either:
- Adjust env.yml (drop the offending pin, add a missing channel), or
- Fall back to the original tarball from `MMSciCode/mmsci-envs-tmp` root:
  `huggingface-cli download MMSciCode/mmsci-envs-tmp --include '<env>.tar.gz' --local-dir $OUT_DIR`

## Step 4 β€” build Docker images

Get the Dockerfile (from the source repo or the HF `docker_build/` upload):

```bash
PACKS_DIR=/home/mmsci/conda_packs \
DOCKERFILE=/home/mmsci/configs_repo/Dockerfile.conda-env \
IMAGE_PREFIX=mmsci-py \
JOBS=2 \
bash /home/mmsci/configs_repo/remote/build_docker_images.sh
```

Each env -> `mmsci-py-<sanitized-name>:latest`. The Dockerfile is the
unmodified `Dockerfile.conda-env` β€” it only does `COPY tarball; tar -xzf;
conda-unpack`, so build time per image is whatever your disk can write
the tarball at (~30s–2min per image).

## Troubleshooting

**`PackageNotFoundError` during `mamba env create`**
The Tsinghua/Aliyun mirrors don't have every conda-forge package. Try:
```bash
mamba env create -n <env> -f configs/<env>/env.yml \
    --override-channels -c conda-forge -c defaults
```
If still missing, the explicit URL list often works:
```bash
conda create -n <env> --file configs/<env>/explicit.txt
```
(URLs point to anaconda.org which is reachable but slow; consider setting
`CONDA_SUBDIR=linux-64`.)

**`pip install` connection errors**
Confirm `~/.config/pip/pip.conf` is in effect: `pip config list`. Some
git+https URLs in `pip-freeze.txt` may need a proxy; consider running the
build under `https_proxy=...` if you have a corporate proxy.

**`conda-pack` editable-packages error**
build_envs_remote.sh passes `--ignore-editable-packages` so this should not
happen. If it does, the env has an editable install that wasn't recorded in
`editable.txt` β€” re-export from the source machine.