File size: 11,736 Bytes
c8b42eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
#!/usr/bin/env python3
"""
Script to prepare dependencies for offline installation.

This script downloads all necessary wheel files for offline installation
of UniCeption in environments without internet access.
"""

import argparse
import os
import subprocess
import sys
from pathlib import Path


def download_wheels(output_dir: Path, extras: list = None):
    """Download wheel files for offline installation."""
    output_dir.mkdir(parents=True, exist_ok=True)

    # Create temporary requirements files
    temp_dir = output_dir / "temp"
    temp_dir.mkdir(exist_ok=True)

    try:
        # Create requirements files
        create_requirements_files(temp_dir, extras)

        # Download base dependencies
        base_cmd = [
            sys.executable,
            "-m",
            "pip",
            "download",
            "--dest",
            str(output_dir),
            "-r",
            str(temp_dir / "requirements-base.txt"),
        ]

        print(f"Downloading base dependencies to {output_dir}...")
        subprocess.check_call(base_cmd)

        # Download optional dependencies if requested
        if extras:
            for extra in extras:
                if extra == "all":
                    # Download all extras
                    for req_file in ["requirements-xformers.txt", "requirements-dev.txt"]:
                        if (temp_dir / req_file).exists():
                            cmd = [
                                sys.executable,
                                "-m",
                                "pip",
                                "download",
                                "--dest",
                                str(output_dir),
                                "-r",
                                str(temp_dir / req_file),
                            ]
                            print(
                                f"Downloading {req_file.replace('requirements-', '').replace('.txt', '')} dependencies..."
                            )
                            try:
                                subprocess.check_call(cmd)
                            except subprocess.CalledProcessError as e:
                                print(f"Warning: Failed to download {extra} dependencies: {e}")
                else:
                    req_file = temp_dir / f"requirements-{extra}.txt"
                    if req_file.exists():
                        cmd = [sys.executable, "-m", "pip", "download", "--dest", str(output_dir), "-r", str(req_file)]
                        print(f"Downloading {extra} dependencies...")
                        try:
                            subprocess.check_call(cmd)
                        except subprocess.CalledProcessError as e:
                            print(f"Warning: Failed to download {extra} dependencies: {e}")

        # Create final offline installation files
        create_offline_installation_files(output_dir)

        print("Download completed successfully!")

    except subprocess.CalledProcessError as e:
        print(f"Error downloading wheels: {e}")
        sys.exit(1)
    finally:
        # Clean up temporary files
        import shutil

        if temp_dir.exists():
            shutil.rmtree(temp_dir)


def create_requirements_files(temp_dir: Path, extras: list = None):
    """Create temporary requirements files for downloading."""

    # Base requirements (including PyTorch)
    base_reqs = [
        "numpy",
        "torch",
        "torchvision",
        "torchaudio",
        "timm",
        "black",
        "jaxtyping",
        "matplotlib",
        "Pillow",
        "scikit-learn",
        "einops",
        "rerun-sdk",
        "pre-commit",
        "minio",
        "pytest",
        "isort",
    ]

    # Write base requirements
    with open(temp_dir / "requirements-base.txt", "w") as f:
        for req in base_reqs:
            f.write(f"{req}\n")

    # XFormers requirements
    with open(temp_dir / "requirements-xformers.txt", "w") as f:
        f.write("xformers\n")

    # Dev requirements
    dev_reqs = [
        "black",
        "isort",
        "pre-commit",
        "pytest",
    ]

    with open(temp_dir / "requirements-dev.txt", "w") as f:
        for req in dev_reqs:
            f.write(f"{req}\n")


def create_offline_installation_files(output_dir: Path):
    """Create requirements files and installation script for offline use."""

    # Base requirements (including PyTorch)
    base_reqs = [
        "numpy",
        "torch",
        "torchvision",
        "torchaudio",
        "timm",
        "black",
        "jaxtyping",
        "matplotlib",
        "Pillow",
        "scikit-learn",
        "einops",
        "rerun-sdk",
        "pre-commit",
        "minio",
        "pytest",
        "isort",
    ]

    # Write base requirements
    with open(output_dir / "requirements-base.txt", "w") as f:
        for req in base_reqs:
            f.write(f"{req}\n")

    # XFormers requirements
    with open(output_dir / "requirements-xformers.txt", "w") as f:
        f.write("xformers\n")

    # Dev requirements
    dev_reqs = [
        "black",
        "isort",
        "pre-commit",
        "pytest",
    ]

    with open(output_dir / "requirements-dev.txt", "w") as f:
        for req in dev_reqs:
            f.write(f"{req}\n")

    # Create installation script
    install_script = output_dir / "install_offline.sh"
    with open(install_script, "w") as f:
        f.write(
            """#!/bin/bash
# Offline installation script for UniCeption

set -e

echo "Installing UniCeption dependencies offline..."

# Check if we're in the right directory
if [ ! -f "requirements-base.txt" ]; then
    echo "Error: requirements-base.txt not found. Please run this script from the offline_wheels directory."
    exit 1
fi

# Install base dependencies (includes PyTorch)
echo "Installing base dependencies (including PyTorch)..."
pip install --no-index --find-links . -r requirements-base.txt

# Install XFormers if requested
if [ "$INSTALL_XFORMERS" = "true" ]; then
    echo "Installing XFormers..."
    pip install --no-index --find-links . -r requirements-xformers.txt
fi

# Install dev dependencies if requested
if [ "$INSTALL_DEV" = "true" ]; then
    echo "Installing development dependencies..."
    pip install --no-index --find-links . -r requirements-dev.txt
fi

# Navigate back to UniCeption directory and install the package
echo "Installing UniCeption package..."
cd ..
pip install --no-deps -e .

# Install CroCo RoPE extension if requested
if [ "$INSTALL_CROCO_ROPE" = "true" ]; then
    echo "Installing CroCo RoPE extension..."
    cd uniception/models/libs/croco/curope
    python setup.py build_ext --inplace
    cd -
fi

echo "Offline installation completed successfully!"
echo ""
echo "To verify installation, run:"
echo "python setup.py check_deps"
"""
        )

    # Make script executable
    install_script.chmod(0o755)

    # Create Windows batch script as well
    install_bat = output_dir / "install_offline.bat"
    with open(install_bat, "w") as f:
        f.write(
            """@echo off
REM Offline installation script for UniCeption (Windows)

echo Installing UniCeption dependencies offline...

REM Check if we're in the right directory
if not exist "requirements-base.txt" (
    echo Error: requirements-base.txt not found. Please run this script from the offline_wheels directory.
    exit /b 1
)

REM Install base dependencies (includes PyTorch)
echo Installing base dependencies (including PyTorch)...
pip install --no-index --find-links . -r requirements-base.txt

REM Install XFormers if requested
if "%INSTALL_XFORMERS%"=="true" (
    echo Installing XFormers...
    pip install --no-index --find-links . -r requirements-xformers.txt
)

REM Install dev dependencies if requested
if "%INSTALL_DEV%"=="true" (
    echo Installing development dependencies...
    pip install --no-index --find-links . -r requirements-dev.txt
)

REM Navigate back to UniCeption directory and install the package
echo Installing UniCeption package...
cd ..
pip install --no-deps -e .

REM Install CroCo RoPE extension if requested
if "%INSTALL_CROCO_ROPE%"=="true" (
    echo Installing CroCo RoPE extension...
    cd uniception\\models\\libs\\croco\\curope
    python setup.py build_ext --inplace
    cd ..\\..\\..\\..\\..
)

echo Offline installation completed successfully!
echo.
echo To verify installation, run:
echo python setup.py check_deps
"""
        )

    # Create a README for offline installation
    readme_file = output_dir / "README_OFFLINE.md"
    with open(readme_file, "w") as f:
        f.write(
            """# UniCeption Offline Installation

This directory contains all the necessary files for installing UniCeption without internet access.

## Files Included

- `requirements-base.txt` - Core dependencies (including PyTorch)
- `requirements-xformers.txt` - XFormers dependency
- `requirements-dev.txt` - Development dependencies
- `install_offline.sh` - Installation script for Unix/Linux/macOS
- `install_offline.bat` - Installation script for Windows
- `*.whl` files - Downloaded wheel packages

## Installation Instructions

### Unix/Linux/macOS

```bash
# Set environment variables for optional components
export INSTALL_XFORMERS=true        # Install XFormers
export INSTALL_DEV=true             # Install development tools
export INSTALL_CROCO_ROPE=true      # Compile CroCo RoPE extension

# Run the installation script
./install_offline.sh
```

### Windows

```cmd
REM Set environment variables for optional components
set INSTALL_XFORMERS=true
set INSTALL_DEV=true
set INSTALL_CROCO_ROPE=true

REM Run the installation script
install_offline.bat
```

## Manual Installation

If the scripts don't work, you can install manually:

```bash
# Install base dependencies (includes PyTorch)
pip install --no-index --find-links . -r requirements-base.txt

# Install optional dependencies as needed
pip install --no-index --find-links . -r requirements-xformers.txt
pip install --no-index --find-links . -r requirements-dev.txt

# Install UniCeption package (from parent directory)
cd ..
pip install --no-deps -e .

# Compile CroCo RoPE extension (optional)
cd uniception/models/libs/croco/curope
python setup.py build_ext --inplace
```

## Verification

After installation, verify everything is working:

```bash
cd ..  # Go back to UniCeption root directory
python setup.py check_deps
```

## Notes

- PyTorch, TorchVision, and TorchAudio are now included in the base requirements
- XFormers is optional and only needed for certain performance optimizations
- CroCo RoPE extension compilation requires a CUDA-enabled environment
"""
        )

    print(f"Created offline installation files in {output_dir}")
    print("Files created:")
    print("  - requirements-base.txt (includes PyTorch)")
    print("  - requirements-xformers.txt")
    print("  - requirements-dev.txt")
    print("  - install_offline.sh (Unix/Linux/macOS)")
    print("  - install_offline.bat (Windows)")
    print("  - README_OFFLINE.md")


def create_offline_requirements(output_dir: Path):
    """Create requirements files for offline installation."""
    # This function is now replaced by create_offline_installation_files
    pass


def main():
    parser = argparse.ArgumentParser(description="Prepare UniCeption for offline installation")
    parser.add_argument(
        "--output-dir", type=Path, default="offline_wheels", help="Directory to store downloaded wheels"
    )
    parser.add_argument("--extras", nargs="+", choices=["xformers", "dev", "all"], help="Extra dependencies to include")

    args = parser.parse_args()

    download_wheels(args.output_dir, args.extras)


if __name__ == "__main__":
    main()