Galliano (2018) – A dust spectral energy distribution model with hierarchical Bayesian inference – I. Formalism and benchmarking