rikunarita-2 commited on
Commit
03bf791
·
verified ·
1 Parent(s): 9f91b0f

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +23 -19
Dockerfile CHANGED
@@ -69,30 +69,34 @@ RUN wget -nv -c https://huggingface.co/circlestone-labs/Anima/resolve/main/split
69
  RUN mkdir temp && chmod 777 temp
70
 
71
  # ------------------------------------------------
72
- # 5. 起動コマンド(cgroupsによる割り当てコア数の厳密な自動検知)
73
  # ------------------------------------------------
74
- # 💡 誤検知防止: ホストの物理コア数ではく、cgroups (v1/v2) リソス制限から
75
- # コンテナに真に割り当てられている実効コア数(Quota / Period)動的に算出します。
76
- CMD export COMPUTE_CORES=$(python3 -c " \
77
- import os, math; \
78
- q_v2='/sys/fs/cgroup/cpu.max'; \
79
- q_v1='/sys/fs/cgroup/cpu/cpu.cfs_quota_us'; \
80
- p_v1='/sys/fs/cgroup/cpu/cpu.cfs_period_us'; \
81
- limit=0; \
82
- if os.path.exists(q_v2): \
83
- v=open(q_v2).read().split(); \
84
- if len(v)==2 and v[0]!='max': limit=math.ceil(float(v[0])/float(v[1])); \
85
- elif os.path.exists(q_v1) and os.path.exists(p_v1): \
86
- q=float(open(q_v1).read()); p=float(open(p_v1).read()); \
87
- if q>0 and p>0: limit=math.ceil(q/p); \
88
- if limit<=0: \
89
- try: limit=len(os.sched_getaffinity(0)) \
90
- except: limit=os.cpu_count() or 1; \
91
- print(max(1, limit))") && \
 
 
 
92
  export OMP_NUM_THREADS=$COMPUTE_CORES && \
93
  export MKL_NUM_THREADS=$COMPUTE_CORES && \
94
  export OMP_PROC_BIND=CLOSE && \
95
  export OMP_PLACES=CORES && \
 
96
  python main.py \
97
  --cpu \
98
  --listen 0.0.0.0 \
 
69
  RUN mkdir temp && chmod 777 temp
70
 
71
  # ------------------------------------------------
72
+ # 5. 起動コマンド(シェルスクリプトによる安全かつ厳密なコア数自動検知)
73
  # ------------------------------------------------
74
+ # 💡 完璧修正:Pythonインデントエラを徹底排除。
75
+ # Linux標準のシェル演算 $(( (quota + period - 1) / period )) 使い、
76
+ # cgroupsから割り当てられた実効コア数を安全かつ正確に自動計算(切り上げ)します。
77
+ CMD quota_v2="/sys/fs/cgroup/cpu.max"; \
78
+ quota_v1="/sys/fs/cgroup/cpu/cpu.cfs_quota_us"; \
79
+ period_v1="/sys/fs/cgroup/cpu/cpu.cfs_period_us"; \
80
+ COMPUTE_CORES=""; \
81
+ if [ -f "$quota_v2" ]; then \
82
+ read -r q p < "$quota_v2"; \
83
+ if [ "$q" != "max" ] && [ "$p" -gt 0 ]; then \
84
+ COMPUTE_CORES=$(( (q + p - 1) / p )); \
85
+ fi; \
86
+ elif [ -f "$quota_v1" ] && [ -f "$period_v1" ]; then \
87
+ q=$(cat "$quota_v1"); p=$(cat "$period_v1"); \
88
+ if [ "$q" -gt 0 ] && [ "$p" -gt 0 ]; then \
89
+ COMPUTE_CORES=$(( (q + p - 1) / p )); \
90
+ fi; \
91
+ fi; \
92
+ if [ -z "$COMPUTE_CORES" ] || [ "$COMPUTE_CORES" -le 0 ]; then \
93
+ COMPUTE_CORES=$(nproc); \
94
+ fi; \
95
  export OMP_NUM_THREADS=$COMPUTE_CORES && \
96
  export MKL_NUM_THREADS=$COMPUTE_CORES && \
97
  export OMP_PROC_BIND=CLOSE && \
98
  export OMP_PLACES=CORES && \
99
+ echo "=== 🚀 Detected Allocated CPU Cores: $COMPUTE_CORES ===" && \
100
  python main.py \
101
  --cpu \
102
  --listen 0.0.0.0 \