Title: Speed Comparison: BitLinear and nn.Linear · Issue #118 · microsoft/BitBLAS · GitHub
Open Graph Title: Speed Comparison: BitLinear and nn.Linear · Issue #118 · microsoft/BitBLAS
X Title: Speed Comparison: BitLinear and nn.Linear · Issue #118 · microsoft/BitBLAS
Description: Hello, I measured the time of your BitLinear and BitLinearBitBLAS against nn.Linear, and it seems that the time for smaller input_features and out_features is slower than nn.Linear. Is there a solution for this? I used the quant_utils fr...
Open Graph Description: Hello, I measured the time of your BitLinear and BitLinearBitBLAS against nn.Linear, and it seems that the time for smaller input_features and out_features is slower than nn.Linear. Is there a solu...
X Description: Hello, I measured the time of your BitLinear and BitLinearBitBLAS against nn.Linear, and it seems that the time for smaller input_features and out_features is slower than nn.Linear. Is there a solu...
Opengraph URL: https://github.com/microsoft/BitBLAS/issues/118
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Speed Comparison: BitLinear and nn.Linear","articleBody":"Hello,\r\n\r\nI measured the time of your BitLinear and BitLinearBitBLAS against nn.Linear, and it seems that the time for smaller input_features and out_features is slower than nn.Linear. Is there a solution for this?\r\n\r\nI used the quant_utils from your BitNet integration: https://github.com/microsoft/BitBLAS/blob/main/integration/BitNet/utils_quant.py\r\n\r\nMy GPU is NVIDIA GeForce RTX 3090\r\n\r\n```\r\nimport time\r\nimport torch\r\nimport torch.nn as nn\r\nfrom torch.autograd import Variable\r\n\r\n# from bitlinear import BitLinear, BitLinearBitBLAS\r\nfrom utils_quant import BitLinear, BitLinearBitBLAS\r\n\r\n# Function to measure computation time\r\ndef measure_time(layer, input_tensor, num_runs=100):\r\n with torch.no_grad():\r\n # Warm up\r\n for _ in range(100): ## 100\r\n _ = layer(input_tensor)\r\n \r\n start_time = time.time()\r\n for _ in range(num_runs):\r\n _ = layer(input_tensor)\r\n torch.cuda.synchronize() #### new\r\n end_time = time.time()\r\n \r\n avg_time = (end_time - start_time) / num_runs\r\n return avg_time\r\n\r\n# # # Test parameters\r\ninput_features = 512\r\noutput_features = 256\r\nbatch_size = 8\r\n\r\n# input_features = 1024\r\n# output_features = 512\r\n# batch_size = 32\r\n\r\n# input_features = 10240\r\n# output_features = 5120\r\n# batch_size = 32\r\n\r\n# input_features = 20480\r\n# output_features = 10240\r\n# batch_size = 32\r\n\r\n\r\n# Create random input tensor\r\ninput_tensor = torch.randn(batch_size, input_features).cuda()\r\n\r\n# Initialize layers\r\nnn_linear_layer = nn.Linear(input_features, output_features).cuda()\r\nbit_linear_layer = BitLinear(input_features, output_features).cuda()\r\n\r\nbitblas_linear_layer = BitLinearBitBLAS.from_bit_linear(bit_linear_layer)\r\n\r\n# Measure computation time\r\nnum_runs = 100\r\nnn_linear_time = measure_time(nn_linear_layer, input_tensor, num_runs)\r\nbit_linear_time = measure_time(bit_linear_layer, input_tensor, num_runs)\r\nbitblas_linear_time = measure_time(bitblas_linear_layer, input_tensor, num_runs)\r\n\r\nprint('input_features, output_features, batch_size: ', input_features, output_features, batch_size)\r\nprint(f\"Average computation time for nn.Linear: {nn_linear_time * 1000:.4f} ms\")\r\nprint(f\"Average computation time for fp32 simulated BitLinear: {bit_linear_time * 1000:.4f} ms\")\r\nprint(f\"Average computation time Bitblas BitLinear: {bitblas_linear_time * 1000:.4f} ms\")\r\n\r\n\r\n```\r\n\r\nHere are the testing results:\r\n\r\n```\r\ninput_features, output_features, batch_size: 512 256 8\r\nAverage computation time for nn.Linear: 0.0230 ms\r\nAverage computation time for fp32 simulated BitLinear: 0.3450 ms\r\nAverage computation time Bitblas BitLinear: 0.3091 ms\r\n\r\ninput_features, output_features, batch_size: 1024 512 32\r\nAverage computation time for nn.Linear: 0.0265 ms\r\nAverage computation time for fp32 simulated BitLinear: 0.3427 ms\r\nAverage computation time Bitblas BitLinear: 0.3137 ms\r\n\r\ninput_features, output_features, batch_size: 10240 5120 32\r\nAverage computation time for nn.Linear: 0.5421 ms\r\nAverage computation time for fp32 simulated BitLinear: 6.3314 ms\r\nAverage computation time Bitblas BitLinear: 0.3170 ms\r\n\r\ninput_features, output_features, batch_size: 20480 10240 32\r\nAverage computation time for nn.Linear: 2.1726 ms\r\nAverage computation time for fp32 simulated BitLinear: 25.2509 ms\r\nAverage computation time Bitblas BitLinear: 0.5633 ms\r\n```\r\n\r\nThanks for your reply in advance.","author":{"url":"https://github.com/ZiqingChang","@type":"Person","name":"ZiqingChang"},"datePublished":"2024-08-01T13:19:30.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":12},"url":"https://github.com/118/BitBLAS/issues/118"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b1aa7d9f-f19e-29c3-1ea2-861f8753b81a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9824:147F26:1A956B8:246D43F:6A4C09CE |
| html-safe-nonce | 66f38f9a3da6c385d0b747f4fea6683826f18a099592d7c7290772f70ce9252d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5ODI0OjE0N0YyNjoxQTk1NkI4OjI0NkQ0M0Y6NkE0QzA5Q0UiLCJ2aXNpdG9yX2lkIjoiNzM2ODA2MjY3NjM0Mzk4MjU0MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 411363eefeabdbef20706ea5b3d37a0f50b7ba70e000d1df0d6c8c6f688034f2 |
| hovercard-subject-tag | issue:2442443338 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/BitBLAS/118/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f8aeab0d9bd4d98f9c2e3e64761efb470728282c05dec3a70b24397c2bd8ddca/microsoft/BitBLAS/issues/118 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f8aeab0d9bd4d98f9c2e3e64761efb470728282c05dec3a70b24397c2bd8ddca/microsoft/BitBLAS/issues/118 |
| og:image:alt | Hello, I measured the time of your BitLinear and BitLinearBitBLAS against nn.Linear, and it seems that the time for smaller input_features and out_features is slower than nn.Linear. Is there a solu... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ZiqingChang |
| hostname | github.com |
| expected-hostname | github.com |
| None | 940b0dbb4d0fe72558ee760b2ff0f25a504383fdfe404f3a7691ec853b8dc17f |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/BitBLAS git https://github.com/microsoft/BitBLAS.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 762181983 |
| octolytics-dimension-repository_nwo | microsoft/BitBLAS |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 762181983 |
| octolytics-dimension-repository_network_root_nwo | microsoft/BitBLAS |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b0267d17ea43e55446153a7e2c60bb6ac3cffd6b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width