Can we fuse blockwise layers with different, but compatible annotations for retries, priority, etc.
()
| 418 | |
| 419 | |
| 420 | def test_optimize_blockwise_control_annotations(): |
| 421 | """ |
| 422 | Can we fuse blockwise layers with different, but compatible |
| 423 | annotations for retries, priority, etc. |
| 424 | """ |
| 425 | |
| 426 | a = da.ones(10, chunks=(5,)) |
| 427 | b = a + 1 |
| 428 | |
| 429 | with dask.annotate(retries=5, workers=["a", "b", "c"], allow_other_workers=False): |
| 430 | c = b + 2 |
| 431 | |
| 432 | with dask.annotate(priority=2, workers=["b", "c", "d"], allow_other_workers=True): |
| 433 | d = c + 3 |
| 434 | |
| 435 | with dask.annotate(retries=3, resources={"GPU": 2, "Memory": 10}): |
| 436 | e = d + 4 |
| 437 | |
| 438 | with dask.annotate(priority=4, resources={"GPU": 5, "Memory": 4}): |
| 439 | f = e + 5 |
| 440 | |
| 441 | # This one will not be fused due to the custom annotation, nor will the one below |
| 442 | with dask.annotate(foo="bar"): |
| 443 | g = f + 6 |
| 444 | |
| 445 | h = g + 6 |
| 446 | |
| 447 | dsk = da.optimization.optimize_blockwise(h.dask) |
| 448 | |
| 449 | # The layers and their annotations should be fusable until the custom one |
| 450 | assert len(dsk.layers) == 3 |
| 451 | layer = hlg_layer_topological(dsk, 0) # First layer is the fused one |
| 452 | annotations = layer.annotations |
| 453 | |
| 454 | assert len(annotations) == 5 |
| 455 | assert annotations["priority"] == 4 # max |
| 456 | assert annotations["retries"] == 5 # max |
| 457 | assert annotations["allow_other_workers"] is False # More restrictive |
| 458 | assert set(annotations["workers"]) == {"b", "c"} # intersection |
| 459 | assert annotations["resources"] == {"GPU": 5, "Memory": 10} # Max of resources |
| 460 | |
| 461 | # If we disable blockwise annotation fusion, we can only fuse the first two layers. |
| 462 | with dask.config.set({"optimization.annotations.fuse": False}): |
| 463 | dsk = da.optimization.optimize_blockwise(h.dask) |
| 464 | assert len(dsk.layers) == 7 |
| 465 | |
| 466 | |
| 467 | def test_optimize_blockwise_custom_annotations(): |
nothing calls this directly
no test coverage detected