{"id":15973731,"url":"https://github.com/c-bata/onnx-remove-random-normal","last_synced_at":"2025-09-03T00:43:16.501Z","repository":{"id":76859454,"uuid":"437327172","full_name":"c-bata/onnx-remove-random-normal","owner":"c-bata","description":"Automatically replace ONNX's RandomNormal node with Constant node.","archived":false,"fork":false,"pushed_at":"2021-12-11T16:05:48.000Z","size":21,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-04T16:28:19.937Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/c-bata.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}},"created_at":"2021-12-11T16:05:19.000Z","updated_at":"2023-08-08T16:50:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"70873808-f178-4149-9bae-04e867e42dfb","html_url":"https://github.com/c-bata/onnx-remove-random-normal","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/c-bata/onnx-remove-random-normal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c-bata%2Fonnx-remove-random-normal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c-bata%2Fonnx-remove-random-normal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c-bata%2Fonnx-remove-random-normal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c-bata%2Fonnx-remove-random-normal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/c-bata","download_url":"https://codeload.github.com/c-bata/onnx-remove-random-normal/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c-bata%2Fonnx-remove-random-normal/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266342809,"owners_count":23914262,"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","status":"online","status_checked_at":"2025-07-21T11:47:31.412Z","response_time":64,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"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":[],"created_at":"2024-10-07T21:06:44.675Z","updated_at":"2025-07-21T17:31:51.898Z","avatar_url":"https://github.com/c-bata.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# onnx-remove-random-normal\n\nThis is a script to replace RandomNormal node with Constant node.\n\n## Example\n\nImagine that we have something ONNX model like the following:\n\n```python\nimport torch\n\n\nclass SomethingModel(torch.nn.Module):\n    def __init__(self):\n        super().__init__()\n\n    def forward(self, x: torch.Tensor):\n        y = torch.tensor([-1, 2], dtype=torch.float32)  # Constant node\n        z = torch.randn(2, dtype=torch.float32)  # RandomNormal node\n        return x + y + z\n\n\ndef export_onnx(path: str) -\u003e None:\n    x = torch.tensor([10, 20], dtype=torch.float32)\n    model = SomethingModel()\n    model.eval()\n\n    torch.onnx.export(\n        model, x, path,\n        verbose=True,\n        export_params=True,\n        do_constant_folding=False,\n        opset_version=11,\n        input_names=['x'],\n        output_names=['output'],\n    )\n```\n\n`torch.randn(...)` will be converted into `RandomNormal` node in ONNX.\nHowever, we can replace it with something constants in some cases.\n\n```\n$ python onnx_remove_random_normal.py --help\nusage: onnx_remove_random_normal.py [-h] [--seed SEED] source output\n\nReplace ONNX RandomNormal node with Constant Node\n\npositional arguments:\n  source       source onnx file\n  output       output onnx file\n\noptional arguments:\n  -h, --help   show this help message and exit\n  --seed SEED  random seed\n$ python onnx_remove_random_normal.py before.onnx after.onnx\n```\n\n| Before | After |\n| --- | --- |\n| ![Before](before.png) | ![After](after.png) |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc-bata%2Fonnx-remove-random-normal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fc-bata%2Fonnx-remove-random-normal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc-bata%2Fonnx-remove-random-normal/lists"}