Design and Optimization of Hierarchical Gradient Coding for Distributed Learning at Edge Devices