How to customize scheduler for ensemble models?

Say I have 4 models, A, B, C, D, they are “Tree” relationship:

Model A is primary model, B, C, and D are secondary models.

Image input into model A, and model A determind which secondary model should be inference. Images maybe input into 0 or all secondary models based on primary model’s result.

Image -> A -> B
          |-> C
          |-> D

How to implement the above procedure?