Some approaches to machine learning (ML) such as Boltzmann machines (BM) can be reformulated as energy based models, which are famous for being trained by minimization of free energy. In the standard contrastive divergence (CD) learning the model parameters optimization is driven by competition of relaxation forces appearing in the target system and the model one. It is tempting to implement a physical device having natural relaxation dynamics matching minimization of the loss function of the ML model. In the article, we propose a general approach for the design of such devices. We systematically reduce the BM, the restricted BM and BM for classification problems to energy based models. For each model we describe a device capable of learning model parameters by relaxation. We compare simulated dynamics of the models using CD, Monte-Carlo method and Langevin dynamics. Benchmarks of the proposed devices on generation and classification of hand-written digits from MNIST dataset are provided. KEYWORDS Machine learning, Boltzmann machine, energy based model, dissipative training. ACKNOWLEDGEMENTS The work is supported by Russian Science Foundation grant 22-22-00565: https://rscf.ru/en/project/22-22-00565/ FOR CITATION Lobanov I.S. Toward nanomagnetic implementation of energy-based machine learning. Nanosystems: