How would you build a lightweight version of PyTorch from scratch, including memory management and computational graphs?