Skip to content

Clean up minor code smells across Python and C++ sources#544

Open
ZabaHD4K wants to merge 1 commit intomicrosoft:mainfrom
ZabaHD4K:fix/python-code-smells
Open

Clean up minor code smells across Python and C++ sources#544
ZabaHD4K wants to merge 1 commit intomicrosoft:mainfrom
ZabaHD4K:fix/python-code-smells

Conversation

@ZabaHD4K
Copy link
Copy Markdown

During one of our regular pair programming sessions, we were browsing through the codebase and noticed a handful of small things that are easy to overlook in a fast-moving project — the kind of stuff that nobody prioritizes because it never breaks anything, but quietly adds up over time.

None of these are critical, but we figured it was worth cleaning them up in a single pass while we had fresh eyes on the code.

Changes

  • Replace bare except clauses with specific exception types (OSError, ValueError)
  • Remove duplicate import sys / from pathlib import Path in generate-dummy-bitnet-model.py
  • Fix .format(i) calls on config keys that had no {} placeholders — they silently did nothing
  • Use os.path.join() instead of string concatenation for building file paths (matters on Windows)
  • Fix exit(0) being used for an error condition — should be sys.exit(1)
  • Translate a few leftover Chinese comments to English for consistency
  • Fix typo in macro name: TVM_ENBALE_EFFICIENT_SMEM_PTR_CASTTVM_ENABLE_EFFICIENT_SMEM_PTR_CAST
  • Remove unused #include <iostream> from CUDA kernel header
  • Rename loop variable os that was shadowing the os module import
  • Use C++ standard headers (<cassert>, <cstring>) instead of C equivalents in .cpp files

- Replace bare except clauses with specific exception types
  (test_perplexity.py, quantize_embeddings.py)
- Remove duplicate imports of sys and pathlib.Path
  (generate-dummy-bitnet-model.py)
- Fix no-op .format() calls on config key strings that had no
  placeholders (codegen_tl1.py, codegen_tl2.py)
- Use os.path.join() instead of string concatenation for file
  paths (codegen_tl1.py, codegen_tl2.py)
- Use sys.exit(1) instead of exit(0) for unsupported arch error
  (setup_env.py)
- Translate remaining Chinese comments to English
  (quantize_embeddings.py, tune_gemm_config.py)
- Fix typo ENBALE -> ENABLE in macro name and remove unused
  iostream include (bitnet_kernels.h)
- Rename variable that shadowed the os module
  (quantize_embeddings.py)
- Use C++ headers instead of C headers in C++ sources
  (ggml-bitnet-lut.cpp, ggml-bitnet-mad.cpp)

Co-Authored-By: Carlos Valés <123006395+carlosvales@users.noreply.github.com>
@ZabaHD4K
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant