Optical lithography is a critical step in the semiconductor manufacturing process, and one key problem is the design of the photomask for a particular circuit pattern, given the optical aberrations and diffraction effects associated with the small feature size. Inverse lithography synthesizes an optimal mask by treating the design as an image synthesis inverse problem. To date, much effort is dedicated to solving it for some nominal process conditions. However, the small feature size also suggests that the effect of process variations is more pronounced. In this paper, we design a mask that is robust against focus variations within the inverse lithography framework. Each iteration involves more computation than a similar method designed for the nominal conditions, but we simplify the task by using stochastic gradient descent, which is a technique from machine learning. Simulation shows that the proposed algorithm is effective in producing robust masks.