Skip to content

Add device/import utilities, expose vectorize/devectorize methods as public callables - #83

Merged
crowbat merged 1 commit into
apple:mainfrom
crowbat:u/k_hsieh/kmeans_palettizer_refactoring
Sep 3, 2026
Merged

Add device/import utilities, expose vectorize/devectorize methods as public callables#83
crowbat merged 1 commit into
apple:mainfrom
crowbat:u/k_hsieh/kmeans_palettizer_refactoring

Conversation

@crowbat

@crowbat crowbat commented Sep 1, 2026

Copy link
Copy Markdown
Contributor
  • Expose utilities for determining whether cuda nvcc and triton are available
  • Bundle vectorize/devectorize logic into public callable methods

@anotheranshu anotheranshu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the comments are blocking

"""
if shutil.which("nvcc") is not None:
return True
return CUDA_HOME is not None and os.path.isfile(os.path.join(CUDA_HOME, "bin", "nvcc"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need/want this fallback, or should we assume that users have CUDA_HOME on their PATH?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CUDA_HOME is a commonly used env var that is set when cuda /cuda nvcc gets installed, and I think it's common for it to not be in PATH which shutil looks for (but checking for both allows us to cover all bases).

sample_weight = None
if block_sensitivity is not None:
sens_vectorized = self._vectorize(block_sensitivity)
sens_vectorized = self._vectorize_block(block_sensitivity)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (and not really this PR): can we rename sens_ to sensitivity_?

"""
weight_shape, weight_dtype = weight.shape, weight.dtype
blocks, axis = self._scale_reshape_and_block(weight)
block_shape = blocks[0].shape # all blocks share one shape

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we validate this and error out here if there are misshapen blocks?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh hmm nvm we do verify this deep down the call stack of _scale_reshape_and_block. I am a little concerned that we're relying on the check so far away, but given that we aren't forking to multiple implementations under the hood I think it's fine

@crowbat
crowbat merged commit 440ecc4 into apple:main Sep 3, 2026
13 checks passed
@crowbat
crowbat deleted the u/k_hsieh/kmeans_palettizer_refactoring branch September 3, 2026 21:42
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.

2 participants