{"id":18293459,"url":"https://github.com/archinetai/quantizer-pytorch","last_synced_at":"2026-05-01T19:34:38.075Z","repository":{"id":57942742,"uuid":"529240763","full_name":"archinetai/quantizer-pytorch","owner":"archinetai","description":"Different vector quantization methods, in PyTorch.","archived":false,"fork":false,"pushed_at":"2022-10-16T21:14:44.000Z","size":26,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-09-20T18:58:45.998Z","etag":null,"topics":["deep-learning","machine-learning","pytorch","quantization"],"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/archinetai.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}},"created_at":"2022-08-26T12:02:30.000Z","updated_at":"2023-07-25T15:00:57.000Z","dependencies_parsed_at":"2022-08-26T22:52:44.702Z","dependency_job_id":null,"html_url":"https://github.com/archinetai/quantizer-pytorch","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/archinetai/quantizer-pytorch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archinetai%2Fquantizer-pytorch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archinetai%2Fquantizer-pytorch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archinetai%2Fquantizer-pytorch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archinetai%2Fquantizer-pytorch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/archinetai","download_url":"https://codeload.github.com/archinetai/quantizer-pytorch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archinetai%2Fquantizer-pytorch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32510808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"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":["deep-learning","machine-learning","pytorch","quantization"],"created_at":"2024-11-05T14:24:39.705Z","updated_at":"2026-05-01T19:34:38.055Z","avatar_url":"https://github.com/archinetai.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Quantizer - PyTorch\n\nDifferent vector quantization methods, in PyTorch.\n\n```bash\npip install quantizer-pytorch\n```\n[![PyPI - Python Version](https://img.shields.io/pypi/v/quantizer-pytorch?style=flat\u0026colorA=black\u0026colorB=black)](https://pypi.org/project/quantizer-pytorch/)\n\n## Usage\n\n### Timewise Quantizer 1d\n```py\nfrom quantizer_pytorch import Quantizer1d\n\nquantizer = Quantizer1d(\n    channels=32,\n    num_groups=1,\n    codebook_size=1024,\n    num_residuals=2\n)\nquantizer.eval() # If the model is set to training mode quantizer will train with EMA by simply forwarding values\n\n# Quantize sequence of shape [batch_size, channels, length]\nx = torch.randn(1, 32, 80)\nx_quantized, info = quantizer(x)\n\nprint(info.keys())                  # ['indices', 'loss', 'perplexity', 'replaced_codes']\nprint(x_quantized.shape)            # [1, 32, 80], same as input but quantized\nprint(info['indices'].shape)        # [1, 1, 80, 2], i.e. [batch, num_groups, length, num_residuals]\nprint(info['loss'])                 # 0.8637, the mean squared error between x and x_quantized\nprint(info['perplexity'])           # [70.3995, 67.5581], a metric used to check the codebook usage of each codebook (max=codebook_size)\nprint(info['replaced_codes'])       # [0, 0], number of replaced codes per group\nprint(info['budget'].shape)         # [num_residuals * num_groups, codebook_size], budget of each codebook element\n\n# Reconstruct x_quantized from indices\nx_quantiezed_recon = quantizer.from_ids(info['indices'])\nassert torch.allclose(x_quantized, x_quantiezed_recon) # This assert should pass if in eval mode\n```\n\n\n### Channelwise Quantizer 1d\n```py\nfrom quantizer_pytorch import QuantizerChannelwise1d\n\nquantizer = QuantizerChannelwise1d(\n    channels=32,\n    split_size=4, # Each channels will be split into vectors of size split_size and quantized\n    num_groups=1,\n    codebook_size=1024,\n    num_residuals=1\n)\nquantizer.eval() # If the model is set to training mode quantizer will train with EMA by simply forwarding values\n\n# Quantize sequence of shape [batch_size, channels, length]\nx = torch.randn(1, 32, 80)\nx_quantized, info = quantizer(x)\n\nprint(info.keys())                  # ['indices', 'loss', 'perplexity', 'replaced_codes']\nprint(x_quantized.shape)            # [1, 32, 80], same as input but quantized\nprint(info['indices'].shape)        # [1, 32, 20], since the length is 80 and we use a split_size (you can think of this as kernel_size=stride=split_size) we have 20 indices\nprint(info['loss'])                 # 0.0620, the mean squared error between x and x_quantized\nprint(info['perplexity'])           # [412.2037], a metric used to check the codebook usage of each codebook (max=codebook_size)\nprint(info['replaced_codes'])       # [1], number of replaced codes per group\nprint(info['budget'].shape)         # [num_residuals * num_groups, codebook_size], budget of each codebook element\n\n# Reconstruct x_quantized from indices\nx_quantiezed_recon = quantizer.from_ids(info['indices'])\nassert torch.allclose(x_quantized, x_quantiezed_recon) # This assert should pass if in eval mode\n```\n\n### Blockwise Quantizer 1d\n```py\nfrom quantizer_pytorch import QuantizerBlock1d\n\nquantizer = QuantizerBlock1d(\n    channels=32,\n    split_size=4,\n    num_groups=2,\n    codebook_size=1024,\n    num_residuals=2\n)\nquantizer.eval() # If the model is set to training mode quantizer will train with EMA by simply forwarding values\nx = torch.randn(1, 32, 40)\nx_quantized, info = quantizer(x)\n\nprint(info.keys())                  # ['indices', 'loss', 'perplexity', 'replaced_codes', 'budget']\nprint(x_quantized.shape)            # [1, 32, 40], same as input but quantized\nprint(info['indices'].shape)        # [1, 20, 2], since the length is 80 and we use a split_size (you can think of this as kernel_size=stride=split_size) we have 20 indices\nprint(info['loss'])                 # 0.0620, the mean squared error between x and x_quantized\nprint(info['perplexity'])           # [20.0000, 18.6607], a metric used to check the codebook usage of each codebook (max=codebook_size)\nprint(info['replaced_codes'])       # [0, 0], number of replaced codes per codebook\nprint(info['budget'].shape)         # [2, 1024], budget of each codebook element\n\n# Reconstruct x_quantized from indices\nx_quantiezed_recon = quantizer.from_ids(info['indices'])\nassert torch.allclose(x_quantized, x_quantiezed_recon) # This assert should pass if in eval mode\n```\n\n## Citations\n\n\n```bibtex\n@misc{2106.04283,\nAuthor = {Rayhane Mama and Marc S. Tyndel and Hashiam Kadhim and Cole Clifford and Ragavan Thurairatnam},\nTitle = {NWT: Towards natural audio-to-video generation with representation learning},\nYear = {2021},\nEprint = {arXiv:2106.04283},\n}\n```\n\n```bibtex\n@misc{2107.03312,\nAuthor = {Neil Zeghidour and Alejandro Luebs and Ahmed Omran and Jan Skoglund and Marco Tagliasacchi},\nTitle = {SoundStream: An End-to-End Neural Audio Codec},\nYear = {2021},\nEprint = {arXiv:2107.03312},\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farchinetai%2Fquantizer-pytorch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farchinetai%2Fquantizer-pytorch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farchinetai%2Fquantizer-pytorch/lists"}