Let $G$ be a finite group. A subset $X$ of $G$ is a set of pairwise non-commuting elements if any two distinct elements of $X$ do not commute. In this paper we determine the maximum size of these subsets in any finite non-abelian metacyclic $2$-group and in any finite non-abelian $p$-group with an abelian maximal subgroup.