Praise be to Allah, the Lord of the World; and blessings and peace be upon our Prophet Muhammad and upon all his Family and Companions.
It is better for the one who prays with a congregation not to leave before his Imaam, for the Hadeeth narrated by At-Tirmithi from Abu Tharr that the Prophet , said: "Whoever stays with his Imaam until the latter leaves, he is given the reward of a Qiyaam of a (whole) night".
But whoever leaves before that, he does not commit anything bad because theTaraweeh prayer is Sunnah and not obligatory.
Allaah knows best.