With the rapid development of Machine Learning (ML), Machine-Learning-as-a-Service (MLaaS) clusters appear in large numbers to support cloud platforms services, which adopt virtual machine (VM) to improve the availability, resilience and security. However, low energy efficiency is a major problem in such clusters. Previous work focused on reducing the number of physical machines by centralizing resources migration. Nevertheless, for ML tasks with frequent memory switching, blind migration is not worth the cost because the remaining time is less than the migration time, since the migration time can not be ignore due to the memory intensive of ML tasks. Therefore, this paper explores how the remaining time and memory replacement states in ML tasks, which we summarize as residue, affect migration, and proposes an online residue-aware migration algorithm based on Lyapunov optimization. Through rigorous proof, the gap between the algorithm and the optimal solution is ensured. Extensive simulations show that the proposed algorithm is better than the previous migration.