{"id":26134358,"url":"https://github.com/pengzhangzhi/path-planning","last_synced_at":"2025-04-13T22:07:01.468Z","repository":{"id":280883711,"uuid":"938975065","full_name":"pengzhangzhi/Path-Planning","owner":"pengzhangzhi","description":"Python package for P2 (Path Planning), a masked diffusion model sampling method for sequence generation (protein, text, etc.).","archived":false,"fork":false,"pushed_at":"2025-03-05T19:48:13.000Z","size":156,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-05T20:51:48.650Z","etag":null,"topics":["deep-learning","diffusion-models","discrete-diffusion-models","pytorch","text-generation"],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/2502.03540 ","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pengzhangzhi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-25T19:44:33.000Z","updated_at":"2025-03-05T19:48:17.000Z","dependencies_parsed_at":"2025-03-05T20:51:52.220Z","dependency_job_id":"32680844-34e1-4d7b-9b2b-821fff10c8bc","html_url":"https://github.com/pengzhangzhi/Path-Planning","commit_stats":null,"previous_names":["pengzhangzhi/path-planning"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pengzhangzhi%2FPath-Planning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pengzhangzhi%2FPath-Planning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pengzhangzhi%2FPath-Planning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pengzhangzhi%2FPath-Planning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pengzhangzhi","download_url":"https://codeload.github.com/pengzhangzhi/Path-Planning/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242945837,"owners_count":20210762,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","diffusion-models","discrete-diffusion-models","pytorch","text-generation"],"created_at":"2025-03-11T00:00:13.231Z","updated_at":"2025-03-11T00:00:14.027Z","avatar_url":"https://github.com/pengzhangzhi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# P2 Sampling\n\nA Python package implementing [P2 (Path Planning)](https://arxiv.org/pdf/2502.03540), a masked diffusion model sampling method for sequence generation. This repository provides a flexible implementation that can be applied to various domains, with example implementations for protein sequence generation and text generation.\n\n## Overview\n\nP2 sampling is a drop-in masked diffusion model sampler. \n\nKey advantages of P2:\n- Simple implementation. The core code is less than 100 LOC.\n-  Modular Components for plug-and-play experimentation.\n- Applicable to various sequence domains (protein, text, etc.)\n\n## Installation\n\n### Basic Installation\n\n```bash\n# Clone the repository\ngit clone git@github.com:pengzhangzhi/path_planning.git\ncd path_planning\n\n# Install the package\npip install -e .\n```\n\n## Examples\n\nThis repository includes example implementations for two domains:\n\n### 1. Protein Sequence Generation\n\nThe protein example demonstrates how to generate novel protein sequences using P2 sampling with ESM-2 models and evaluate their quality using ESMFold.\n\n#### Running the Protein Example\n\n```bash\n# Basic generation\npython examples/protein/generate.py --num_seqs 10 --seq_len 128\n\n# With ESMFold evaluation\npython examples/protein/generate.py --num_seqs 10 --seq_len 128 --esmfold_eval --save_dir results/test_run\n```\n\n#### Jupyter Notebook\n\nFor an interactive demonstration, you can also use the Jupyter notebook:\n\n```bash\nexamples/protein/p2_sampling_demo.ipynb\n```\n\n### 2. Text Generation (LLaDA)\n\nThe text example implements [LLaDA](https://arxiv.org/abs/2502.09992), a diffusion-based text generation approach using language models.\n\n#### Running the Text Example\n\n```bash\n# Navigate to the text example directory\ncd examples/text/LLaDA\n\n# Run the generation script\npython generate.py\n```\n\n#### Chat Example\n\n```bash\ncd examples/text/LLaDA\npython chat.py\n```\nHere is an example of my chat history:\n\n![alt text](assets/chat_example.png)\n\n## API Usage\n\nYou can use the P2 sampling functionality programmatically in your own projects:\n\n```python\nfrom path_planning import p2_sampling, seed_everything\nfrom path_planning.score_function import logP\n\n# Set random seed for reproducibility\nseed_everything(42)\n\n# Create a model decorator that makes the model return logits\nModelWrapper = lambda model: lambda x: model(x).logits\n\nmodel_wrapper = ModelWrapper(your_model)\n\n# Use P2 sampling in your code\nsampled_sequence = p2_sampling(\n    xt=initial_masked_sequence,\n    model=model_wrapper,\n    mask_id=your_mask_token_id,\n    num_steps=128,\n    tau=1.0,\n    eta=1.0,\n    score_fn=logP\n)\n```\n\n## Appreciation\n\nThe code is based on the following repository:\n\n- [DPLM](https://github.com/bytedance/dplm)\n- [LLaDA](https://github.com/ML-GSAI/LLaDA)\n\n\n## Citation\n\n```bibtex\n@misc{peng2025pathplanningmaskeddiffusion,\n      title={Path Planning for Masked Diffusion Model Sampling}, \n      author={Fred Zhangzhi Peng and Zachary Bezemek and Sawan Patel and Jarrid Rector-Brooks and Sherwood Yao and Alexander Tong and Pranam Chatterjee},\n      year={2025},\n      eprint={2502.03540},\n      archivePrefix={arXiv},\n      primaryClass={cs.LG},\n      url={https://arxiv.org/abs/2502.03540}, \n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpengzhangzhi%2Fpath-planning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpengzhangzhi%2Fpath-planning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpengzhangzhi%2Fpath-planning/lists"}