The Messenger of Allah ﷺ said, "Whoever among you fears that he will not wake up at the end of the night, let him pray witr at the beginning of the night and then sleep. Whoever among you is confident that he will wake up at the end of the night, let him pray witr at the end of the night, for the recitation at the end of the night is witnessed, and that is better."
حدثنا عبد الله بن سعيد حدثنا ابن أبي غنية حدثنا الأعمش عن أبي سفيان
عن رسول الله ﷺ قال من خاف منكم أن لا يستيقظ من آخر الليل فليوتر من أول الليل ثم ليرقد ومن طمع منكم أن يستيقظ من آخر الليل فليوتر من آخر الليل فإن قراءة آخر الليل محضورة وذلك أفضل
Muslim narrated it in the Book of the Prayer of Travelers, in the chapter "Whoever fears that he will not wake up at the end of the night should pray witr at its beginning," hadith no. 755, from the hadith of Amash through this same chain.