1Heat oven to 325°F and arrange a rack in the middle. Spray an 8-by-8-inch square baking dish with nonstick cooking spray.
2Melt 1/2 cup of the margarine in a saucepan over medium heat. When it foams, sprinkle in 2/3 cup of the sugar, 1/2 teaspoon of the apple pie spice, and vanilla extract. Stir over medium heat until sauce is smooth and a deep amber color.
3Spread caramel sauce evenly in bottom of baking dish. Tile apple slices in tight rows over sauce. Sprinkle lemon juice over apple slices. Evenly sprinkle walnuts on top, if using.
4Combine flour, baking powder, and remaining 1/2 teaspoon of the apple pie spice in a large bowl and mix thoroughly. Add remaining 1 cup of the sugar, remaining 1/2 cup of the margarine, and eggs. Beat on medium speed until a thick batter forms. Add soy milk and stir until evenly combined.
5Transfer batter to prepared dish and spread over apples. Bake until a toothpick inserted in cake layer comes out clean, about 45 to 55 minutes. Invert onto serving platter and serve warm or room temperature.