Abstract: We establish a method to compute the Nekrasov partition functions of theories which arises from (p, q) 5-brane webs or M-theory compactifications on their dual Calabi-Yau threefolds.The theories include certain non-Lagrangian theories such as the T_N theory. For that, it is important to remove the contributions which are decoupled from the theory. The web diagram encodes the decoupled contributions in a simple way.We also develop a prescription to compute the instanton partition functions of theories which are obtained by the Higgsing the T_N theory. The theories include the Sp(1) gauge theories with 6 or 7 flavors which have E7 or E8 flavor symmetry respectively at their fixed points.