attong39 commited on
Commit
499bc4b
·
verified ·
1 Parent(s): f523f14

Upload Dockerfile with huggingface_hub

Browse files
Files changed (1) hide show
  1. Dockerfile +80 -92
Dockerfile CHANGED
@@ -1,92 +1,80 @@
1
- FROM nvidia/cuda:12.4.1-cudnn-devel-ubuntu22.04
2
-
3
- # Build arg for GPU architectures - specify which CUDA compute capabilities to compile for
4
- # Common values:
5
- # 7.0 - Tesla V100
6
- # 7.5 - RTX 2060, 2070, 2080, Titan RTX
7
- # 8.0 - A100, A800 (Ampere data center)
8
- # 8.6 - RTX 3060, 3070, 3080, 3090 (Ampere consumer)
9
- # 8.9 - RTX 4070, 4080, 4090 (Ada Lovelace)
10
- # 9.0 - H100, H800 (Hopper data center)
11
- # 12.0 - RTX 5070, 5080, 5090 (Blackwell) - Note: sm_120 architecture
12
- #
13
- # Examples:
14
- # RTX 3060: --build-arg CUDA_ARCHITECTURES="8.6"
15
- # RTX 4090: --build-arg CUDA_ARCHITECTURES="8.9"
16
- # Multiple: --build-arg CUDA_ARCHITECTURES="8.0;8.6;8.9"
17
- #
18
- # Note: Including 8.9 or 9.0 may cause compilation issues on some setups
19
- # Default includes 8.0 and 8.6 for broad Ampere compatibility
20
- ARG CUDA_ARCHITECTURES="8.0;8.6"
21
-
22
- ENV DEBIAN_FRONTEND=noninteractive
23
-
24
- # Install system dependencies
25
- RUN apt update && \
26
- apt install -y \
27
- python3 python3-pip git wget curl cmake ninja-build \
28
- libgl1 libglib2.0-0 ffmpeg && \
29
- apt clean
30
-
31
- WORKDIR /workspace
32
-
33
- COPY requirements.txt .
34
-
35
- # Upgrade pip first
36
- RUN pip install --upgrade pip setuptools wheel
37
-
38
- # Install requirements if exists
39
- RUN pip install -r requirements.txt
40
-
41
- # Install PyTorch with CUDA support
42
- RUN pip install --extra-index-url https://download.pytorch.org/whl/cu124 \
43
- torch==2.6.0+cu124 torchvision==0.21.0+cu124
44
-
45
- # Install SageAttention from git (patch GPU detection)
46
- ENV TORCH_CUDA_ARCH_LIST="${CUDA_ARCHITECTURES}"
47
- ENV FORCE_CUDA="1"
48
- ENV MAX_JOBS="1"
49
-
50
- COPY <<EOF /tmp/patch_setup.py
51
- import os
52
- with open('setup.py', 'r') as f:
53
- content = f.read()
54
-
55
- # Get architectures from environment variable
56
- arch_list = os.environ.get('TORCH_CUDA_ARCH_LIST')
57
- arch_set = '{' + ', '.join([f'"{arch}"' for arch in arch_list.split(';')]) + '}'
58
-
59
- # Replace the GPU detection section
60
- old_section = '''compute_capabilities = set()
61
- device_count = torch.cuda.device_count()
62
- for i in range(device_count):
63
- major, minor = torch.cuda.get_device_capability(i)
64
- if major < 8:
65
- warnings.warn(f"skipping GPU {i} with compute capability {major}.{minor}")
66
- continue
67
- compute_capabilities.add(f"{major}.{minor}")'''
68
-
69
- new_section = 'compute_capabilities = ' + arch_set + '''
70
- print(f"Manually set compute capabilities: {compute_capabilities}")'''
71
-
72
- content = content.replace(old_section, new_section)
73
-
74
- with open('setup.py', 'w') as f:
75
- f.write(content)
76
- EOF
77
-
78
- RUN git clone https://github.com/thu-ml/SageAttention.git /tmp/sageattention && \
79
- cd /tmp/sageattention && \
80
- python3 /tmp/patch_setup.py && \
81
- pip install --no-build-isolation .
82
-
83
- RUN useradd -u 1000 -ms /bin/bash user
84
-
85
- RUN chown -R user:user /workspace
86
-
87
- RUN mkdir /home/user/.cache && \
88
- chown -R user:user /home/user/.cache
89
-
90
- COPY entrypoint.sh /workspace/entrypoint.sh
91
-
92
- ENTRYPOINT ["/workspace/entrypoint.sh"]
 
1
+ FROM nvidia/cuda:12.4.1-cudnn-devel-ubuntu22.04
2
+
3
+ # Build arg for GPU architectures
4
+ ARG CUDA_ARCHITECTURES="8.0;8.6"
5
+
6
+ ENV DEBIAN_FRONTEND=noninteractive
7
+
8
+ # Install system dependencies
9
+ RUN apt update && \
10
+ apt install -y \
11
+ python3 python3-pip git wget curl cmake ninja-build \
12
+ libgl1 libglib2.0-0 ffmpeg && \
13
+ apt clean
14
+
15
+ WORKDIR /workspace
16
+
17
+ COPY requirements.txt .
18
+
19
+ # Upgrade pip first
20
+ RUN pip install --upgrade pip setuptools wheel
21
+
22
+ # Install requirements if exists
23
+ RUN pip install -r requirements.txt
24
+
25
+ # Install PyTorch with CUDA support
26
+ RUN pip install --extra-index-url https://download.pytorch.org/whl/cu124 \
27
+ torch==2.6.0+cu124 torchvision==0.21.0+cu124
28
+
29
+ # Install SageAttention from git (patch GPU detection)
30
+ ENV TORCH_CUDA_ARCH_LIST="${CUDA_ARCHITECTURES}"
31
+ ENV FORCE_CUDA="1"
32
+ ENV MAX_JOBS="1"
33
+
34
+ COPY <<EOF /tmp/patch_setup.py
35
+ import os
36
+ with open('setup.py', 'r') as f:
37
+ content = f.read()
38
+
39
+ # Get architectures from environment variable
40
+ arch_list = os.environ.get('TORCH_CUDA_ARCH_LIST')
41
+ arch_set = '{' + ', '.join([f'"{arch}"' for arch in arch_list.split(';')]) + '}'
42
+
43
+ # Replace the GPU detection section
44
+ old_section = '''compute_capabilities = set()
45
+ device_count = torch.cuda.device_count()
46
+ for i in range(device_count):
47
+ major, minor = torch.cuda.get_device_capability(i)
48
+ if major < 8:
49
+ warnings.warn(f"skipping GPU {i} with compute capability {major}.{minor}")
50
+ continue
51
+ compute_capabilities.add(f"{major}.{minor}")'''
52
+
53
+ new_section = 'compute_capabilities = ' + arch_set + '''
54
+ print(f"Manually set compute capabilities: {compute_capabilities}")'''
55
+
56
+ content = content.replace(old_section, new_section)
57
+
58
+ with open('setup.py', 'w') as f:
59
+ f.write(content)
60
+ EOF
61
+
62
+ RUN git clone https://github.com/thu-ml/SageAttention.git /tmp/sageattention && \
63
+ cd /tmp/sageattention && \
64
+ python3 /tmp/patch_setup.py && \
65
+ pip install --no-build-isolation .
66
+
67
+ # --- FIX: Copy application code ---
68
+ COPY . /workspace
69
+ # ----------------------------------
70
+
71
+ RUN useradd -u 1000 -ms /bin/bash user
72
+
73
+ RUN chown -R user:user /workspace
74
+
75
+ RUN mkdir /home/user/.cache && \
76
+ chown -R user:user /home/user/.cache
77
+
78
+ COPY entrypoint.sh /workspace/entrypoint.sh
79
+
80
+ ENTRYPOINT ["/workspace/entrypoint.sh"]