  Many important graph theoretic notions can be encoded as counting graph
homomorphism problems, such as partition functions in statistical physics, in
particular, independent sets and colourings. In this article we study the
complexity of $\#_p\mathsf{H}$OMS$\mathsf{T}$O$H$, the problem of counting
graph homomorphisms from an input graph to a graph $H$ modulo a prime number
$p$. Dyer and Greenhill proved a dichotomy stating that the tractability of
non-modular counting graph homomorphisms depends on the structure of the input
graph. Many intractable cases in non-modular counting become tractable in
modular counting due to the common phenomenon of cancellation. However, in
subsequent studies on counting modulo $2$ the influence, the structure of $H$
has on the tractability, was shown to persist, yielding similar dichotomies.
  Our main result shows that for every tree $H$ and every prime $p$ the problem
$\#_p\mathsf{H}$OMS$\mathsf{T}$O$H$ is either polynomial time computable or
$\#_p\mathsf{P}$-complete. This addresses the conjecture of Faben and Jerrum
stating this dichotomy for every graph $H$ when counting modulo 2. In order to
prove this result, we study the structural properties of a homomorphism. As an
important interim, this study yields a dichotomy for the problem of weighted
counting independent sets in a bipartite graph modulo some prime $p$. Our
results are the first suggesting that such dichotomies hold not only for the
one-bit functions of the modulo~2 case but for the modular counting functions
of all primes $p$.
