Closely. Those who created the game engine were very knowledgeable on the DnD subject. Their deviations are easy to understand from a gameplay perspective.
With BG3 this is different. Here the engine already exists. Larian has its own vision of what makes a good RPG and the engine was tailored to meet those objectives. As a result, in BG3 most deviations seem inherited rather than created on purpose.