Skip to content

Commit

Permalink
Merge pull request #54 from MPI-Dortmund/random-port
Browse files Browse the repository at this point in the history
Use random port for distributed processing
  • Loading branch information
thorstenwagner authored Oct 16, 2023
2 parents baa8da2 + 002fcde commit dd8a6b4
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/checks_tests_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools setuptools_scm pylint tox tox-gh-actions pytest pytest-coverage twine build
pip install setuptools setuptools_scm pylint==2.17.7 tox tox-gh-actions pytest pytest-coverage twine build
pip install .
- name: Debug Info
run: |
Expand Down
17 changes: 10 additions & 7 deletions scripts/molmapsbbox.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
from skimage.measure import label, regionprops
import numpy as np
import argparse
import json
import os
from typing import List

import mrcfile
import numpy as np
import skimage.measure as skm

from tomotwin.modules.common.preprocess import label_filename
import argparse
import os
import json


def binarize(vol):
t = np.max(vol) - (np.max(vol) - np.min(vol)) * 0.9
return vol > t

def boxsize(vol):
lbl = label(vol, background=0)
regs = regionprops(lbl)
lbl = skm.label(vol, background=0)
regs = skm.regionprops(lbl)
size = -1
for reg in regs:
cand_size = np.max([np.abs(reg.bbox[i] - reg.bbox[i+3]) for i in range(int(len(reg.bbox)/2))])
Expand Down
4 changes: 4 additions & 0 deletions tests/test_embed_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ def test_embed_main_real_subvol_torchembeddor(self):
)
@pytest.mark.skipif(torch.cuda.is_available() == False, reason="Skipped because CUDA is not available")
def test_embed_main_real_subvol_distributedtorchembeddor(self):
import random
os.environ['MASTER_ADDR'] = '127.0.0.1'
os.environ['MASTER_PORT'] = '29' + str(random.randint(1, 500)).zfill(3)

from tomotwin.embed_main import run as embed_main_func

tomo = np.random.randn(37, 37, 37).astype(np.float32)
Expand Down
3 changes: 3 additions & 0 deletions tomotwin/embed_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@
import glob
import hashlib
import os
import random
import resource
import sys
from typing import List
Expand Down Expand Up @@ -605,6 +606,8 @@ def run_distr(config, world_size: int):
f"Your user limit ('ulimit -n') is too low ({limit[0]}). Please run 'ulimit -n 65000' before running tomotwin_embed.")
sys.exit(1)
print(f"Found {world_size} GPU(s). Start DDP + Compiling.")
os.environ['MASTER_ADDR'] = '127.0.0.1'
os.environ['MASTER_PORT'] = '29' + str(random.randint(1, 500)).zfill(3)
mp.spawn(
run,
args=([config, world_size]),
Expand Down
6 changes: 4 additions & 2 deletions tomotwin/modules/common/io/mrc_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,10 @@
class MrcFormat:
@staticmethod
def read(pth: str) -> np.array:
vol = None
try:
vol = mrcfile.open(pth, mode="r", permissive=True)
with mrcfile.open(pth, mode="r", permissive=True) as mrc:
vol = mrc.data
except ValueError as e:
raise Exception(f"Failed reading {pth}") from e
return vol.data
return vol
4 changes: 0 additions & 4 deletions tomotwin/modules/inference/embedor.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@
defined by the Mozilla Public License, v. 2.0.
"""

import os
from abc import ABC, abstractmethod

import numpy as np
Expand Down Expand Up @@ -522,9 +521,6 @@ def __init__(
workers: int = 0,
) -> None:
"""Inits the embedor"""

os.environ['MASTER_ADDR'] = '127.0.0.1'
os.environ['MASTER_PORT'] = '29500'
tdist.init_process_group(backend='gloo', rank=rank, world_size=world_size)
tdist.barrier()
self.rank = rank
Expand Down
3 changes: 1 addition & 2 deletions tomotwin/modules/networks/SiameseNet3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,7 @@ def forward(self, inputtensor):
Forward pass through the network
:param inputtensor: Input tensor
"""

inputtensor = nn.functional.pad(inputtensor, (1, 2, 1, 2, 1, 2))
inputtensor = F.pad(inputtensor, (1, 2, 1, 2, 1, 2))

out = self.conv_layer0(inputtensor)
out = self.max_pooling(out)
Expand Down

0 comments on commit dd8a6b4

Please sign in to comment.