Skip to content

Commit

Permalink
Acquire locks before mp.Value updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mryab committed Nov 4, 2024
1 parent aa9caf4 commit 0590954
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion tests/test_moe.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ def test_client_anomaly_detection():
def _measure_coro_running_time(n_coros, elapsed_fut, counter):
async def coro():
await asyncio.sleep(0.1)
counter.value += 1
with counter.get_lock():
counter.value += 1

try:
start_time = time.perf_counter()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@ def run_trainer(batch_size: int, batch_time: float, client_mode: bool):
loss.backward()

optimizer.step()

total_samples_accumulated.value += batch_size
with total_samples_accumulated.get_lock():
total_samples_accumulated.value += batch_size

if not reuse_grad_buffers:
optimizer.zero_grad()
Expand Down

0 comments on commit 0590954

Please sign in to comment.