to support gradient and parameter collection and serialisation for external optimisers