The best solution I’ve found so far is to ditch the mask and instead add a feature that takes value 1 if the row is padded (not real data), 0 otherwise, and then include that feature in the model. While it’s not the most efficient, in simulations doing this made it possible to recover the correct weights on the other features successfully.