Historical data has shown that the natural gas pipeline network, as a critical urban lifeline system, is susceptible to disasters such as earthquakes resulting in leakage. Graph neural network modeling provides frontier rapid detection solutions for pipeline leakage; however, the challenges of collecting gas network anomaly data for training limit the precision and robustness of current model. This research proposes an unsupervised gas leakage detection and localization method based on a contained preprocessing process, with a graph deviation model that combines a structural learning approach with a graph neural network to model the spatial dependence of the sensors based on an attention mechanism, and variational inference models the posterior distributions of the hyper-parameters to optimize the model and improve the model precision. Meanwhile, in the preprocessing stage, the automatic optimization strategy of Northern Goshawk Optimization (NGO) for the best parameters K and ɑ in the Variable Mode Decomposition (VMD) efficiently extracts the valid signals and ensures that the model gives full play to the detection and localization effectiveness. The gas pipeline network dataset constructed by Pipeline Studio was used for comparing the performance of the model in this study with other frontier models. The results demonstrate that the model in this research has competitive detection Precision (93.31%), Recall (70.82%), and F1-score (0.81), and the posterior distribution of the model parameters strengthens the gas leakage localization precision, which provides a comprehensive solution for subsequent decision-making and reduces the hidden hazard of leakage effectively.