I will discuss scalar-tensor models of gravity, which predict the spontaneous scalarization of neutron stars or/and black holes. In the cosmological setup, the scalar field responsible for scalarization is subject to a tachyonic instability during inflation as well as at other cosmological stages, depending on the model. The instability poses a problem for viability of such models. I will show that for the case of scalarization with the Gauss-Bonnet term, a catastrophic instability develops during inflation within a period of time much shorter than the minimum required duration of inflation. As a result, the standard cosmological dynamics is not recovered. On the other hand, in the case of standard scalarization by Damour-Esposito-Farese, it is possible to make a simple modification of the original model by coupling the scalar to the inflaton field. For generic couplings the scalar (including its perturbations) relaxes to zero with an exponential accuracy by the beginning of the hot stage.