Ashish Ajin
commited on
Commit
Β·
64ff81d
1
Parent(s):
bcd0453
Compile diffvg with CUDA
Browse files- Dockerfile +7 -1
- README.md +9 -3
- code/main.py +8 -3
Dockerfile
CHANGED
|
@@ -35,8 +35,14 @@ RUN pip install --upgrade pip \
|
|
| 35 |
# ββ Build diffvg from a known-good commit ββββββββββ
|
| 36 |
RUN git clone https://github.com/BachiLi/diffvg.git /tmp/diffvg \
|
| 37 |
&& cd /tmp/diffvg \
|
|
|
|
| 38 |
&& git submodule update --init --recursive \
|
| 39 |
-
&&
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
&& cd /app \
|
| 41 |
&& rm -rf /tmp/diffvg
|
| 42 |
|
|
|
|
| 35 |
# ββ Build diffvg from a known-good commit ββββββββββ
|
| 36 |
RUN git clone https://github.com/BachiLi/diffvg.git /tmp/diffvg \
|
| 37 |
&& cd /tmp/diffvg \
|
| 38 |
+
&& git checkout 7aa22d3f1ef72e22e5cfae3c8c50288f31bc9bcf \
|
| 39 |
&& git submodule update --init --recursive \
|
| 40 |
+
&& mkdir build && cd build \
|
| 41 |
+
&& cmake .. -DCMAKE_BUILD_TYPE=Release -DUSE_CUDA=ON \
|
| 42 |
+
-DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc \
|
| 43 |
+
&& make -j$(nproc) \
|
| 44 |
+
&& cd ../python && TORCH_CUDA_ARCH_LIST="6.0;7.0;7.5;8.0;8.6;8.9" \
|
| 45 |
+
python setup.py install --user \
|
| 46 |
&& cd /app \
|
| 47 |
&& rm -rf /tmp/diffvg
|
| 48 |
|
README.md
CHANGED
|
@@ -57,9 +57,9 @@ cd Word-As-Image
|
|
| 57 |
```
|
| 58 |
2. Create a new conda environment and install the libraries:
|
| 59 |
```bash
|
| 60 |
-
conda create --name word python=3.
|
| 61 |
conda activate word
|
| 62 |
-
pip install torch
|
| 63 |
conda install -y numpy scikit-image
|
| 64 |
conda install -y -c anaconda cmake
|
| 65 |
conda install -y -c conda-forge ffmpeg
|
|
@@ -79,8 +79,14 @@ pip install transformers scipy ftfy accelerate
|
|
| 79 |
```bash
|
| 80 |
git clone https://github.com/BachiLi/diffvg.git
|
| 81 |
cd diffvg
|
|
|
|
| 82 |
git submodule update --init --recursive
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
```
|
| 85 |
|
| 86 |
5. Paste your HuggingFace [access token](https://huggingface.co/settings/tokens) for StableDiffusion in the TOKEN file.
|
|
|
|
| 57 |
```
|
| 58 |
2. Create a new conda environment and install the libraries:
|
| 59 |
```bash
|
| 60 |
+
conda create --name word python=3.10
|
| 61 |
conda activate word
|
| 62 |
+
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu118
|
| 63 |
conda install -y numpy scikit-image
|
| 64 |
conda install -y -c anaconda cmake
|
| 65 |
conda install -y -c conda-forge ffmpeg
|
|
|
|
| 79 |
```bash
|
| 80 |
git clone https://github.com/BachiLi/diffvg.git
|
| 81 |
cd diffvg
|
| 82 |
+
git checkout 7aa22d3f1ef72e22e5cfae3c8c50288f31bc9bcf
|
| 83 |
git submodule update --init --recursive
|
| 84 |
+
mkdir build && cd build
|
| 85 |
+
cmake .. -DCMAKE_BUILD_TYPE=Release -DUSE_CUDA=ON \
|
| 86 |
+
-DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc
|
| 87 |
+
make -j$(nproc)
|
| 88 |
+
cd ../python && TORCH_CUDA_ARCH_LIST="6.0;7.0;7.5;8.0;8.6;8.9" \
|
| 89 |
+
python setup.py install
|
| 90 |
```
|
| 91 |
|
| 92 |
5. Paste your HuggingFace [access token](https://huggingface.co/settings/tokens) for StableDiffusion in the TOKEN file.
|
code/main.py
CHANGED
|
@@ -55,9 +55,14 @@ def generate_word_image(cfg, device: torch.device):
|
|
| 55 |
if isinstance(cfg, dict):
|
| 56 |
cfg = edict(cfg)
|
| 57 |
|
| 58 |
-
#
|
| 59 |
-
#
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
print(f"experiment directory: {cfg.experiment_dir}")
|
| 63 |
|
|
|
|
| 55 |
if isinstance(cfg, dict):
|
| 56 |
cfg = edict(cfg)
|
| 57 |
|
| 58 |
+
# Use the GPU for rendering when available. If diffvg was compiled
|
| 59 |
+
# without CUDA support this call will fall back to CPU rendering.
|
| 60 |
+
use_gpu = torch.cuda.is_available()
|
| 61 |
+
try:
|
| 62 |
+
pydiffvg.set_use_gpu(use_gpu)
|
| 63 |
+
except Exception as err: # diffvg not built with CUDA
|
| 64 |
+
print(f"Warning: cannot enable CUDA for diffvg ({err}). Falling back to CPU.")
|
| 65 |
+
pydiffvg.set_use_gpu(False)
|
| 66 |
|
| 67 |
print(f"experiment directory: {cfg.experiment_dir}")
|
| 68 |
|