{"id":49107000,"url":"https://github.com/rajcscw/pytorch-optimize","last_synced_at":"2026-04-21T02:01:44.394Z","repository":{"id":56180344,"uuid":"266502949","full_name":"rajcscw/pytorch-optimize","owner":"rajcscw","description":"A simple black-box optimization framework to train your pytorch models for optimizing non-differentiable objectives","archived":false,"fork":false,"pushed_at":"2023-03-05T16:03:12.000Z","size":62,"stargazers_count":11,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-27T14:51:53.557Z","etag":null,"topics":["blackbox-optimization","evolution-strategies","pytorch","reinforcement-learning"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rajcscw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-05-24T08:48:40.000Z","updated_at":"2025-07-01T15:56:13.000Z","dependencies_parsed_at":"2022-08-15T14:10:40.057Z","dependency_job_id":"b597a449-53f1-472c-85d1-e3cc84c726fc","html_url":"https://github.com/rajcscw/pytorch-optimize","commit_stats":{"total_commits":39,"total_committers":1,"mean_commits":39.0,"dds":0.0,"last_synced_commit":"4da25030a09ec53642d209379608f95bdc445740"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/rajcscw/pytorch-optimize","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajcscw%2Fpytorch-optimize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajcscw%2Fpytorch-optimize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajcscw%2Fpytorch-optimize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajcscw%2Fpytorch-optimize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rajcscw","download_url":"https://codeload.github.com/rajcscw/pytorch-optimize/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajcscw%2Fpytorch-optimize/sbom","scorecard":{"id":759919,"data":{"date":"2025-08-11","repo":{"name":"github.com/rajcscw/pytorch-optimize","commit":"4da25030a09ec53642d209379608f95bdc445740"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.4,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/19 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/rajcscw/pytorch-optimize/main.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/rajcscw/pytorch-optimize/main.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/rajcscw/pytorch-optimize/main.yml/master?enable=pin","Warn: pipCommand not pinned by hash: .github/workflows/main.yml:25","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned","Info:   0 out of   1 pipCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/main.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 13 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-22T23:04:02.770Z","repository_id":56180344,"created_at":"2025-08-22T23:04:02.770Z","updated_at":"2025-08-22T23:04:02.770Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32073496,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-21T01:35:38.224Z","status":"online","status_checked_at":"2026-04-21T02:00:06.111Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["blackbox-optimization","evolution-strategies","pytorch","reinforcement-learning"],"created_at":"2026-04-21T02:00:51.288Z","updated_at":"2026-04-21T02:01:44.388Z","avatar_url":"https://github.com/rajcscw.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pytorch-optimize [![CircleCI](https://circleci.com/gh/rajcscw/pytorch-optimize/tree/master.svg?style=svg)](https://circleci.com/gh/rajcscw/pytorch-optimize/tree/master)\n\npytorch-optimize is a simple black-box framework to train pytorch models for optimizing arbitrary objective functions. It provides simple wrappers for models and optimizers so that they can be used to optimize the provided objective function (including non-differentiable objectives). It also supports optimization of multiple objectives out-of-the-box. The optimizer itself is based on\n[Evolution strategies](https://arxiv.org/pdf/1703.03864.pdf) which estimates gradient using parallel workers so that it can scale well utilizing multiple cores.\n\n## Install\n```\ngit clone https://github.com/rajcscw/pytorch-optimize.git\ncd pytorch-optimize\npip install .\n```\n\n## Usage\n\n 1.Wrap your pytorch model (`torch.nn.Module`) using the [`Model`](https://github.com/rajcscw/pytorch-optimize/blob/master/pytorch_optimize/model.py)  class. The Model class automatically extracts the trainable parameters in the network and samples them at each training step. The sampling strategy can be changed by providing it as an argument to the Model class. Possible strategies include sampling layers from bottom to up, top to bottom, random or all the layers at once.\n\n```python\nfrom pytorch_optimize.model import Model, SamplingStrategy\nnet = Net(..)\nmodel = Model(net=net, strategy=SamplingStrategy.BOTTOM_UP)\n```\n\n2.Provide an [`objective function`](https://github.com/rajcscw/pytorch-optimize/blob/master/pytorch_optimize/objective.py) (a callable) which takes the wrapped model and [`samples`](https://github.com/rajcscw/pytorch-optimize/blob/master/pytorch_optimize/objective.py) as its inputs. The objective function then should return a scalar value corresponding to the measurement of objective function. The objective function can also return a list of scalar values, in this case, it corresponds to multiple objective functions.\nNote, here [`Samples`](https://github.com/rajcscw/pytorch-optimize/blob/master/pytorch_optimize/objective.py) is just a simple dataclass for wrapping data for computing the objective function. For instance, in supervised learning, it contains inputs and targets. For reinforcement learning, this could be environments, seeds etc. \n\n\n```python\nfrom pytorch_optimize.objective import Objective, Samples\n\nclass MyObjective(Objective):\n    def __call__(self, model: Model, samples: Samples) -\u003e List[float]\n        # compute your objective function(s)\n        return objectives\n\nmy_objective = MyObjective() \n```\n\n3.Create an instance of the [`ESOptimizer`](https://github.com/rajcscw/pytorch-optimize/blob/master/pytorch_optimize/optimizer.py). This takes an instance of the wrapped model, SGD optimizer and the objective function. Additionally, you have to pass weights corresponding to each of the objective functions using `obj_weights`. Further, parameters `sigma` and `n_samples` for ES have to be passed. Internally, the objectives are subject to rank transformation so the scales of objective function(s) does not influence the optimization.\n\nNote: The optimizer does gradient ascent instead of descent. Therefore, the objective functions needs to be implemented accordingly(for instance, returning 1/loss instead of loss).\n\n```python\nsgd_optimizer = torch.optim.SGD(net.parameters(), lr=1e-2)\nes_optimizer = ESOptimizer(model=model, sgd_optimizer=sgd_optimizer, objective_fn=my_objective, \n                           obj_weights=[1.0],sigma=1e-1, n_samples=100)\n```\n\n4.Write your usual training loop or trainer routine with the following template. \n\n```python\nfor epoch in range(1000):\n    samples = Samples(..)                               # wrap data\n    es_optimizer.gradient_step(samples)                 # gradient step\n    objective_at_epoch = MyObjective()(model, samples)  # measure objective after stepping\n```\n\n## Demo scripts\n\nTwo simple showcases: reinforcement learning and supervised learning are provided in the [sample_scripts](https://github.com/rajcscw/pytorch-optimize/tree/master/sample_scripts) folder:\n\n1.**Supervised Learning:** As an illustrative example, [supervised.py](https://github.com/rajcscw/pytorch-optimize/blob/master/sample_scripts/supervised.py) shows training a classifier to classify MNIST digits by directly optimizing the accuracy rather than cross-entropy loss.\n\n\n2.**Reinforcement Learning:** \nSimilary, the script [rl.py](https://github.com/rajcscw/pytorch-optimize/blob/master/sample_scripts/rl.py) shows how to train an RL agent that tries to maximize the episodic reward it receives while solving the task cart pole balancing task. To run this script, install also [gym](https://github.com/openai/gym).\n\n## Contributions\nYou are welcome to contribute to the repository by developing new features or fixing bugs. If you do so, please create a pull request.\n\n## Cite\n\nIf you use this repository for your research, please cite with the following bibtex:\n\n```\n@software{Ramamurthy_pytorch-optimize_is_a,\nauthor = {Ramamurthy, Rajkumar},\nlicense = {MIT},\ntitle = {{pytorch-optimize is a simple black-box optimisation framework}},\nurl = {https://github.com/rajcscw/pytorch-optimize},\nversion = {0.0.1}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frajcscw%2Fpytorch-optimize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frajcscw%2Fpytorch-optimize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frajcscw%2Fpytorch-optimize/lists"}