# scorenet **Repository Path**: wisestruct/scorenet ## Basic Information - **Project Name**: scorenet - **Description**: 低纬精简版 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-09-09 - **Last Updated**: 2024-10-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # GNOTES - github:langevin-dynamics-and-score-matching - python -c "import torch; print(torch.cuda.is_available())" - 损失值相同 ≠ 梯度相同:即使损失值相同,由于归约方式的不同,梯度计算可能不同,从而影响模型的训练路径。 潜在影响:在简单的模型和任务中,这种差异可能不明显,但在更复杂的模型中(如深度网络、时序数据),这种微小的差异可能会影响收敛速度或最终的模型性能。 - Euler-Maruyama 方法的关键与 Langevin Dynamics 类似,都是通过 score(噪声梯度)的指导来逐步去噪。 - 得分函数(score)是要预测扰动数据相对于标准正态噪声 z 的负梯度,也就是 -∇z log p(z)。 - \ell(\theta; a) = \frac{1}{2} \mathbb{E}_{p_{\text{data}}(x)} \mathbb{E}_{n \sim \mathcal{N}(0, I)} \left[ \left\| s_{\theta}(\tilde{x}, a) + \frac{\tilde{x} - a \cdot x}{(1 - a)^2} \right\|_2^2 \right] - scorematch算法原理上学到的是噪声的反向梯度,这个噪声就是标准噪声,而不是std缩放后的噪声,所有去噪时不断以标准噪声为单位去噪即可 - scoremodel为什么要除以std,原因是它训练时是固定std,所以真实噪声就是std*N0,而它学到是N0的梯度,所以还原是需要对齐到std*N0 - 提交冲突会退到提交前状态: git merge --abort, git reset --hard idbeforecommit # Langevin Dynamics and Score Matching ## How to? ### Setup ``` pip install -r requirements.txt ``` ### Train ``` python3 main.py config/ring.yml train ``` This command produces the model (learnt scaled score function): `ring.pth` ### Test ``` python3 main.py config/ring.yml test ``` This command produces a list of frames at each stage of sampling under `ring/` and an animation `ring.gif` made from them. ## Demo (with carefully tuned hyperparameters) - Left: sample from the real pixel distribution - Right: sample using Langevin dynamics based on the score function learnt via denoising score matching. ### Ring ![ring.gif](./ring.gif) ### Waddles ![waddles.gif](./waddles.gif) ### Stewie ![stewie.gif](./stewie.gif) ## Reference - A good [lecture](https://youtu.be/3-KzIjoFJy4) on Langevin dynamics for sampling. - A [recent paper](https://arxiv.org/pdf/1907.05600.pdf) combining Langevin dynamics with denosing score matching with a more complicated multi-level pertubation scheme. - A [paper](http://www.iro.umontreal.ca/~vincentp/Publications/smdae_techreport.pdf) introducing the denoising score matching.