Let H be a graph allowing loops as well as vertex-and edge-weights. We prove that, for every triangle-free graph G without isolated vertices, the weighted number of graph homomorphisms hom(G, H) satisfies the inequalitywhere du denotes the degree of vertex u in G. In particular, one has hom(G, H) 1/|E(G)| ≤ hom (K d,d , H) 1/d 2 for every d-regular triangle-free G. The triangle-free hypothesis on G is best possible. More generally, we prove a graphical Brascamp-Lieb type inequality, where every edge of G is assigned some two-variable function. These inequalities imply tight upper bounds on the partition function of various statistical models such as the Ising and Potts models, which includes independent sets and graph colorings.For graph colorings, corresponding to H = Kq (also valid if some of the vertices of Kq are looped), we show that the triangle-free hypothesis on G may be dropped. A corollary is that among d-regular graphs, G = K d,d maximizes the quantity cq(G) 1/|V (G)| for every q and d, where cq(G) counts proper q-colorings of G.Finally, we show that if the edge-weight matrix of H is positive semidefinite, thenThis implies that among d-regular graphs, G = K d+1 maximizes hom(G, H) 1/|V (G)| . For 2-spin Ising models, our results give a complete characterization of extremal graphs: complete bipartite graphs maximize the partition function of 2-spin antiferromagnetic models and cliques maximize the partition function of ferromagnetic models. These results settle a number of conjectures by Galvin-Tetali, Galvin, and Cohen-Csikvári-Perkins-Tetali, and provide an alternate proof to a conjecture by Kahn. arXiv:1809.09462v2 [math.CO] , where denotes a disjoint union. Question 1.1 was initially raised by Granville in 1988 in connection with the Cameron-Erdős conjecture on the number of sum-free sets. Alon [1] and Kahn [27] conjectured that G = K d,d is the exact maximizer. Alon [1] proved an asymptotic version as d → ∞, Kahn [27] proved the exact version under the additional hypothesis that G is bipartite, and Zhao [38] later removed this bipartite assumption. The results of Kahn [27] and Zhao [38] together answer Question 1.1: the maximizer is K d,d (unique up to taking disjoint unions of copies of itself). Galvin and Tetali [22] initiated the study of Questions 1.2 and 1.3 and extended Kahn's entropy method [27] to prove that, under the additional hypothesis that G is bipartite, G = K d,d is also the maximizer for hom(G, H) 1/|V (G)| . See Lubetzky and Zhao [32, Section 6] for a different proof using Hölder/Brascamp-Lieb type inequalities. Can the bipartite hypothesis on G also be dropped in this case? Not for all H: e.g., for H = , G = K d+1 is the maximizer instead of K d,d . Extending the technique for independent sets, Zhao [39] showed that the bipartite hypothesis can be dropped for certain classes of H, but the techniques failed for H = K q , corresponding to colorings (Question 1.2). It remained a tantalizing conjecture to remove the bipartite hypothesis for colorings.Recently, Davies, Jenssen, Perki...