Repository navigation
Split large SCCs in parallel mode - #22541
ilevkivskyi wants to merge 4 commits into
Conversation
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
|
Here's a possible bug reported by claude: Bug: a worker can re-analyse an SCC it already loaded from cache What happens:
Reproduced. I used an instrumented copy and added sleeps to force the ordering on one worker: y → X shard 2 → z. Here z imports m0 (in X) and y. Sequential mode reports: The sharded run drops that error (due to extra The ordering needs no unusual timing in a real build. It happens whenever dependents get dispatched while the affinity workers are still checking a large SCC's implementations, which is exactly the case sharding targets. Possible fix: don't hand a pending shard of X to a worker that has already processed anything depending on X. The coordinator can track the SCCs sent to each worker and check them with the existing is_transitive_scc_dep (mypy/build.py:1660). Leaving such a shard to an affinity worker costs only some parallelism. |
|
Another potential bug reported by codex: [P1] Repartitioning a cycle can skip a module’s body checks. The worker recomputes shard membership on every request from mutable size hints. In a two-worker incremental run with a non-ASCII --shadow-file, reparsing changed one module’s hint from byte length to character count. The same worker then checked ring6 twice and skipped ring4, where master reported an incompatible return type. Computing shard membership once from the original size hints would keep assignments stable |
|
@JukkaL You know, I am not doing this for work, I am doing this to interact with people. Anyway, I guess my time contributing to mypy is over now. I may fork it, or maybe I will find something else. |
|
You are right, this was rude of me, and I'm sorry. I shouldn't have copy pasted coding agent output as response for your PR. I'm actually very excited about this PR, but I will be very busy for a few days at least, and I wanted to make some forward progress with code review ASAP. Instead, I should have just left comment saying that I'm busy and will get back to this later or similar instead of outsourcing my code review to an agent. I promise to stop doing this in the future, and I hope that you can reconsider your decision. |
|
What you have done is literally like replying to someone's question with a Google link. Anyway, good luck! |
This makes libraries like
torch~2x faster (tested with-n8), and self-check is up to 10% faster (again for-n8, with fewer workers gains are smaller).Basic idea and technical side are quite straightforward. However, details of the sharding and scheduling logic are quite tricky. This is partially because I made a mistake when measuring interface vs implementation time: right now ~30-40% of time is spent in loading+interface. Most of it is spent in semantic analysis. This makes splitting semantic analysis into two phases imperative, if we want to see full gains from this PR.
Here are some important details of the PR.
First, we need to be sure that splitting will be effective, this means all of these must be true:
Second, we should split eagerly. It is quite common that a large bottleneck SCC arrives in the queue while there is only one free worker. The other will become free soon, so if we don't split, they all will be idling.
Third (the consequence of above), we should minimize interface penalty in case where we have split an SCC, but it was actually not needed. For example, if some other worker soon unblocked a big chunk of parallelizable work. For this purpose I introduce affinity for workers processing sharded SCCs. When a worker becomes free:
Note I also did some refactoring in worker code, since
serve()function grew too large. I didn't do much parameter tuning. I think we should merge this PR, then try splitting the semantic analysis, and then I will do some parameter tuning.cc @JukkaL