I think what you need is toIValue(), or even IValue(toIValue()) that removes c10::optional<> from c10::optional<IValue>.
No idea why we even need this whole c10::optional<> construct when IValue can simply return .isNone() == true — which it actually does after the proposed conversion if the value was empty.