Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backends/arm/quantizer/arm_quantizer.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -1220,6 +1220,10 @@ def set_global(
quantization_config, node_finder, self.pattern_matcher
)
self.global_config = quantization_config
# Let the shared-qspec pass initiate quantization from the global config
# for shared-op clusters that sit on the quantized I/O boundary but have
# no neighbor qspec to propagate (see SharedQspecQuantizer).
self.shared_qspec_quantizer.global_config = quantization_config
return self

def set_node_target(
Expand Down
58 changes: 53 additions & 5 deletions backends/arm/quantizer/arm_quantizer_utils.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -336,14 +336,22 @@ def annotate_match(
f"{node.name} is not expected to not have parameter tensors but found {[n.name for n in params]}, which may cause unexpected quantization annotations."
)

# Only ops in ``parameter_targets`` (conv/linear) have true weight and
# bias operands. For any other op, a parameter input is a constant
# activation operand and must be quantized with the input-activation
# qspec, not the weight qspec. Treating it as a weight breaks ops whose
# TOSA implementation requires both operands to share a dtype (e.g.
# add/sub), and silently demotes constants in int16 (16a8w) modules to
# int8 -- the weight qspec ``dtype`` differs from the activation dtype.
has_weight_and_bias = node.target in parameter_targets
for input_node in node.all_input_nodes:
if not has_float_output(input_node):
continue
if self.is_weight(input_node, params, model):
if has_weight_and_bias and self.is_weight(input_node, params, model):
input_qspec_map[input_node] = (
config.get_weight_qspec(node) if config else None
)
elif self.is_bias(input_node, params, model):
elif has_weight_and_bias and self.is_bias(input_node, params, model):
input_qspec_map[input_node] = (
config.get_bias_qspec(node) if config else None # type: ignore[assignment]
)
Expand DownExpand Up@@ -481,6 +489,10 @@ class SharedQspecQuantizer(Quantizer, QuantizerReporterUser):
def __init__(self, targets: Optional[list[Callable[..., object]]] = None) -> None:
super().__init__()
QuantizerReporterUser.__init__(self)
# Optional global config used to *initiate* quantization for shared-op
# clusters that sit on the quantized I/O boundary but have no neighbor
# qspec to propagate. Set by the composable quantizer's set_global().
self.global_config: Optional[QuantizationConfig] = None
if targets is None:
self.targets = self.SHARED_QSPEC_OPS_DEFAULT
self.support_config_path = (
Expand DownExpand Up@@ -552,10 +564,24 @@ def _append_input_qspec(
return
adjacent_qspecs.append(input_qspec)

def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any]]:
def _is_quantized_io_boundary(self, node: Node) -> bool:
"""Return True if ``node`` is a model input/output the quantizer
annotated.

Such a node sits on the quantized interface, but its qspec is often
filtered out of shared-cluster propagation -- a uint8 IO qspec is skipped
by ``_skip_shared_qspec_from_io``, and an input-state placeholder may
carry an annotation with no ``output_qspec``. Its presence still signals
that the cluster is on the quantized data path.

"""
return node.op in ("placeholder", "output") and self._is_annotated(node)

def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any], bool]:
shared_nodes = set()
bfs_queue = [root_node]
adjacent_qspecs: list[Any] = []
touches_quantized_io = False

while bfs_queue:
node = bfs_queue.pop(0)
Expand All@@ -564,12 +590,14 @@ def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any]]:
for input_node in node.all_input_nodes:
self._maybe_enqueue_shared_node(input_node, shared_nodes, bfs_queue)
self._append_output_qspec(input_node, adjacent_qspecs)
touches_quantized_io |= self._is_quantized_io_boundary(input_node)

for output_node in node.users.keys():
self._maybe_enqueue_shared_node(output_node, shared_nodes, bfs_queue)
self._append_input_qspec(output_node, node, adjacent_qspecs)
touches_quantized_io |= self._is_quantized_io_boundary(output_node)

return shared_nodes, adjacent_qspecs
return shared_nodes, adjacent_qspecs, touches_quantized_io

def _annotate_shared_cluster(self, root_node: Node) -> None:
if (
Expand All@@ -588,7 +616,27 @@ def _annotate_shared_cluster(self, root_node: Node) -> None:
)
return

shared_nodes, adjacent_qspecs = self._get_shared_clique(root_node)
shared_nodes, adjacent_qspecs, touches_quantized_io = self._get_shared_clique(
root_node
)

# If there is no neighbor qspec to propagate but the cluster sits on the
# quantized I/O boundary (e.g. a state-passthrough ``cat`` whose only
# neighbors are a uint8 model input -- skipped by
# _skip_shared_qspec_from_io -- and an input-state placeholder), initiate
# quantization from the global config rather than leaving the cluster in
# float. Otherwise such clusters fall off the integer delegate onto the
# CPU. Initiating from the global (internal) config keeps uint8 confined
# to the IO boundary.
if (
len(adjacent_qspecs) == 0
and touches_quantized_io
and self.global_config is not None
):
global_input_qspec = self.global_config.get_input_act_qspec()
if global_input_qspec is not None:
adjacent_qspecs = [global_input_qspec]

node_order = {node: index for index, node in enumerate(root_node.graph.nodes)}
ordered_nodes = sorted(shared_nodes, key=lambda node: node_order.get(node, 0))

Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backends/arm/quantizer/arm_quantizer.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -1220,6 +1220,10 @@ def set_global(
quantization_config, node_finder, self.pattern_matcher
)
self.global_config = quantization_config
# Let the shared-qspec pass initiate quantization from the global config
# for shared-op clusters that sit on the quantized I/O boundary but have
# no neighbor qspec to propagate (see SharedQspecQuantizer).
self.shared_qspec_quantizer.global_config = quantization_config
return self

def set_node_target(
Expand Down
58 changes: 53 additions & 5 deletions backends/arm/quantizer/arm_quantizer_utils.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -336,14 +336,22 @@ def annotate_match(
f"{node.name} is not expected to not have parameter tensors but found {[n.name for n in params]}, which may cause unexpected quantization annotations."
)

# Only ops in ``parameter_targets`` (conv/linear) have true weight and
# bias operands. For any other op, a parameter input is a constant
# activation operand and must be quantized with the input-activation
# qspec, not the weight qspec. Treating it as a weight breaks ops whose
# TOSA implementation requires both operands to share a dtype (e.g.
# add/sub), and silently demotes constants in int16 (16a8w) modules to
# int8 -- the weight qspec ``dtype`` differs from the activation dtype.
has_weight_and_bias = node.target in parameter_targets
for input_node in node.all_input_nodes:
if not has_float_output(input_node):
continue
if self.is_weight(input_node, params, model):
if has_weight_and_bias and self.is_weight(input_node, params, model):
input_qspec_map[input_node] = (
config.get_weight_qspec(node) if config else None
)
elif self.is_bias(input_node, params, model):
elif has_weight_and_bias and self.is_bias(input_node, params, model):
input_qspec_map[input_node] = (
config.get_bias_qspec(node) if config else None # type: ignore[assignment]
)
Expand DownExpand Up@@ -481,6 +489,10 @@ class SharedQspecQuantizer(Quantizer, QuantizerReporterUser):
def __init__(self, targets: Optional[list[Callable[..., object]]] = None) -> None:
super().__init__()
QuantizerReporterUser.__init__(self)
# Optional global config used to *initiate* quantization for shared-op
# clusters that sit on the quantized I/O boundary but have no neighbor
# qspec to propagate. Set by the composable quantizer's set_global().
self.global_config: Optional[QuantizationConfig] = None
if targets is None:
self.targets = self.SHARED_QSPEC_OPS_DEFAULT
self.support_config_path = (
Expand DownExpand Up@@ -552,10 +564,24 @@ def _append_input_qspec(
return
adjacent_qspecs.append(input_qspec)

def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any]]:
def _is_quantized_io_boundary(self, node: Node) -> bool:
"""Return True if ``node`` is a model input/output the quantizer
annotated.

Such a node sits on the quantized interface, but its qspec is often
filtered out of shared-cluster propagation -- a uint8 IO qspec is skipped
by ``_skip_shared_qspec_from_io``, and an input-state placeholder may
carry an annotation with no ``output_qspec``. Its presence still signals
that the cluster is on the quantized data path.

"""
return node.op in ("placeholder", "output") and self._is_annotated(node)

def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any], bool]:
shared_nodes = set()
bfs_queue = [root_node]
adjacent_qspecs: list[Any] = []
touches_quantized_io = False

while bfs_queue:
node = bfs_queue.pop(0)
Expand All@@ -564,12 +590,14 @@ def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any]]:
for input_node in node.all_input_nodes:
self._maybe_enqueue_shared_node(input_node, shared_nodes, bfs_queue)
self._append_output_qspec(input_node, adjacent_qspecs)
touches_quantized_io |= self._is_quantized_io_boundary(input_node)

for output_node in node.users.keys():
self._maybe_enqueue_shared_node(output_node, shared_nodes, bfs_queue)
self._append_input_qspec(output_node, node, adjacent_qspecs)
touches_quantized_io |= self._is_quantized_io_boundary(output_node)

return shared_nodes, adjacent_qspecs
return shared_nodes, adjacent_qspecs, touches_quantized_io

def _annotate_shared_cluster(self, root_node: Node) -> None:
if (
Expand All@@ -588,7 +616,27 @@ def _annotate_shared_cluster(self, root_node: Node) -> None:
)
return

shared_nodes, adjacent_qspecs = self._get_shared_clique(root_node)
shared_nodes, adjacent_qspecs, touches_quantized_io = self._get_shared_clique(
root_node
)

# If there is no neighbor qspec to propagate but the cluster sits on the
# quantized I/O boundary (e.g. a state-passthrough ``cat`` whose only
# neighbors are a uint8 model input -- skipped by
# _skip_shared_qspec_from_io -- and an input-state placeholder), initiate
# quantization from the global config rather than leaving the cluster in
# float. Otherwise such clusters fall off the integer delegate onto the
# CPU. Initiating from the global (internal) config keeps uint8 confined
# to the IO boundary.
if (
len(adjacent_qspecs) == 0
and touches_quantized_io
and self.global_config is not None
):
global_input_qspec = self.global_config.get_input_act_qspec()
if global_input_qspec is not None:
adjacent_qspecs = [global_input_qspec]

node_order = {node: index for index, node in enumerate(root_node.graph.nodes)}
ordered_nodes = sorted(shared_nodes, key=lambda node: node_order.get(node, 0))

Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backends/arm/quantizer/arm_quantizer.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -1220,6 +1220,10 @@ def set_global(
quantization_config, node_finder, self.pattern_matcher
)
self.global_config = quantization_config
# Let the shared-qspec pass initiate quantization from the global config
# for shared-op clusters that sit on the quantized I/O boundary but have
# no neighbor qspec to propagate (see SharedQspecQuantizer).
self.shared_qspec_quantizer.global_config = quantization_config
return self

def set_node_target(
Expand Down
58 changes: 53 additions & 5 deletions backends/arm/quantizer/arm_quantizer_utils.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -336,14 +336,22 @@ def annotate_match(
f"{node.name} is not expected to not have parameter tensors but found {[n.name for n in params]}, which may cause unexpected quantization annotations."
)

# Only ops in ``parameter_targets`` (conv/linear) have true weight and
# bias operands. For any other op, a parameter input is a constant
# activation operand and must be quantized with the input-activation
# qspec, not the weight qspec. Treating it as a weight breaks ops whose
# TOSA implementation requires both operands to share a dtype (e.g.
# add/sub), and silently demotes constants in int16 (16a8w) modules to
# int8 -- the weight qspec ``dtype`` differs from the activation dtype.
has_weight_and_bias = node.target in parameter_targets
for input_node in node.all_input_nodes:
if not has_float_output(input_node):
continue
if self.is_weight(input_node, params, model):
if has_weight_and_bias and self.is_weight(input_node, params, model):
input_qspec_map[input_node] = (
config.get_weight_qspec(node) if config else None
)
elif self.is_bias(input_node, params, model):
elif has_weight_and_bias and self.is_bias(input_node, params, model):
input_qspec_map[input_node] = (
config.get_bias_qspec(node) if config else None # type: ignore[assignment]
)
Expand DownExpand Up@@ -481,6 +489,10 @@ class SharedQspecQuantizer(Quantizer, QuantizerReporterUser):
def __init__(self, targets: Optional[list[Callable[..., object]]] = None) -> None:
super().__init__()
QuantizerReporterUser.__init__(self)
# Optional global config used to *initiate* quantization for shared-op
# clusters that sit on the quantized I/O boundary but have no neighbor
# qspec to propagate. Set by the composable quantizer's set_global().
self.global_config: Optional[QuantizationConfig] = None
if targets is None:
self.targets = self.SHARED_QSPEC_OPS_DEFAULT
self.support_config_path = (
Expand DownExpand Up@@ -552,10 +564,24 @@ def _append_input_qspec(
return
adjacent_qspecs.append(input_qspec)

def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any]]:
def _is_quantized_io_boundary(self, node: Node) -> bool:
"""Return True if ``node`` is a model input/output the quantizer
annotated.

Such a node sits on the quantized interface, but its qspec is often
filtered out of shared-cluster propagation -- a uint8 IO qspec is skipped
by ``_skip_shared_qspec_from_io``, and an input-state placeholder may
carry an annotation with no ``output_qspec``. Its presence still signals
that the cluster is on the quantized data path.

"""
return node.op in ("placeholder", "output") and self._is_annotated(node)

def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any], bool]:
shared_nodes = set()
bfs_queue = [root_node]
adjacent_qspecs: list[Any] = []
touches_quantized_io = False

while bfs_queue:
node = bfs_queue.pop(0)
Expand All@@ -564,12 +590,14 @@ def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any]]:
for input_node in node.all_input_nodes:
self._maybe_enqueue_shared_node(input_node, shared_nodes, bfs_queue)
self._append_output_qspec(input_node, adjacent_qspecs)
touches_quantized_io |= self._is_quantized_io_boundary(input_node)

for output_node in node.users.keys():
self._maybe_enqueue_shared_node(output_node, shared_nodes, bfs_queue)
self._append_input_qspec(output_node, node, adjacent_qspecs)
touches_quantized_io |= self._is_quantized_io_boundary(output_node)

return shared_nodes, adjacent_qspecs
return shared_nodes, adjacent_qspecs, touches_quantized_io

def _annotate_shared_cluster(self, root_node: Node) -> None:
if (
Expand All@@ -588,7 +616,27 @@ def _annotate_shared_cluster(self, root_node: Node) -> None:
)
return

shared_nodes, adjacent_qspecs = self._get_shared_clique(root_node)
shared_nodes, adjacent_qspecs, touches_quantized_io = self._get_shared_clique(
root_node
)

# If there is no neighbor qspec to propagate but the cluster sits on the
# quantized I/O boundary (e.g. a state-passthrough ``cat`` whose only
# neighbors are a uint8 model input -- skipped by
# _skip_shared_qspec_from_io -- and an input-state placeholder), initiate
# quantization from the global config rather than leaving the cluster in
# float. Otherwise such clusters fall off the integer delegate onto the
# CPU. Initiating from the global (internal) config keeps uint8 confined
# to the IO boundary.
if (
len(adjacent_qspecs) == 0
and touches_quantized_io
and self.global_config is not None
):
global_input_qspec = self.global_config.get_input_act_qspec()
if global_input_qspec is not None:
adjacent_qspecs = [global_input_qspec]

node_order = {node: index for index, node in enumerate(root_node.graph.nodes)}
ordered_nodes = sorted(shared_nodes, key=lambda node: node_order.get(node, 0))

Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backends/arm/quantizer/arm_quantizer.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -1220,6 +1220,10 @@ def set_global(
quantization_config, node_finder, self.pattern_matcher
)
self.global_config = quantization_config
# Let the shared-qspec pass initiate quantization from the global config
# for shared-op clusters that sit on the quantized I/O boundary but have
# no neighbor qspec to propagate (see SharedQspecQuantizer).
self.shared_qspec_quantizer.global_config = quantization_config
return self

def set_node_target(
Expand Down
58 changes: 53 additions & 5 deletions backends/arm/quantizer/arm_quantizer_utils.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -336,14 +336,22 @@ def annotate_match(
f"{node.name} is not expected to not have parameter tensors but found {[n.name for n in params]}, which may cause unexpected quantization annotations."
)

# Only ops in ``parameter_targets`` (conv/linear) have true weight and
# bias operands. For any other op, a parameter input is a constant
# activation operand and must be quantized with the input-activation
# qspec, not the weight qspec. Treating it as a weight breaks ops whose
# TOSA implementation requires both operands to share a dtype (e.g.
# add/sub), and silently demotes constants in int16 (16a8w) modules to
# int8 -- the weight qspec ``dtype`` differs from the activation dtype.
has_weight_and_bias = node.target in parameter_targets
for input_node in node.all_input_nodes:
if not has_float_output(input_node):
continue
if self.is_weight(input_node, params, model):
if has_weight_and_bias and self.is_weight(input_node, params, model):
input_qspec_map[input_node] = (
config.get_weight_qspec(node) if config else None
)
elif self.is_bias(input_node, params, model):
elif has_weight_and_bias and self.is_bias(input_node, params, model):
input_qspec_map[input_node] = (
config.get_bias_qspec(node) if config else None # type: ignore[assignment]
)
Expand DownExpand Up@@ -481,6 +489,10 @@ class SharedQspecQuantizer(Quantizer, QuantizerReporterUser):
def __init__(self, targets: Optional[list[Callable[..., object]]] = None) -> None:
super().__init__()
QuantizerReporterUser.__init__(self)
# Optional global config used to *initiate* quantization for shared-op
# clusters that sit on the quantized I/O boundary but have no neighbor
# qspec to propagate. Set by the composable quantizer's set_global().
self.global_config: Optional[QuantizationConfig] = None
if targets is None:
self.targets = self.SHARED_QSPEC_OPS_DEFAULT
self.support_config_path = (
Expand DownExpand Up@@ -552,10 +564,24 @@ def _append_input_qspec(
return
adjacent_qspecs.append(input_qspec)

def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any]]:
def _is_quantized_io_boundary(self, node: Node) -> bool:
"""Return True if ``node`` is a model input/output the quantizer
annotated.

Such a node sits on the quantized interface, but its qspec is often
filtered out of shared-cluster propagation -- a uint8 IO qspec is skipped
by ``_skip_shared_qspec_from_io``, and an input-state placeholder may
carry an annotation with no ``output_qspec``. Its presence still signals
that the cluster is on the quantized data path.

"""
return node.op in ("placeholder", "output") and self._is_annotated(node)

def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any], bool]:
shared_nodes = set()
bfs_queue = [root_node]
adjacent_qspecs: list[Any] = []
touches_quantized_io = False

while bfs_queue:
node = bfs_queue.pop(0)
Expand All@@ -564,12 +590,14 @@ def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any]]:
for input_node in node.all_input_nodes:
self._maybe_enqueue_shared_node(input_node, shared_nodes, bfs_queue)
self._append_output_qspec(input_node, adjacent_qspecs)
touches_quantized_io |= self._is_quantized_io_boundary(input_node)

for output_node in node.users.keys():
self._maybe_enqueue_shared_node(output_node, shared_nodes, bfs_queue)
self._append_input_qspec(output_node, node, adjacent_qspecs)
touches_quantized_io |= self._is_quantized_io_boundary(output_node)

return shared_nodes, adjacent_qspecs
return shared_nodes, adjacent_qspecs, touches_quantized_io

def _annotate_shared_cluster(self, root_node: Node) -> None:
if (
Expand All@@ -588,7 +616,27 @@ def _annotate_shared_cluster(self, root_node: Node) -> None:
)
return

shared_nodes, adjacent_qspecs = self._get_shared_clique(root_node)
shared_nodes, adjacent_qspecs, touches_quantized_io = self._get_shared_clique(
root_node
)

# If there is no neighbor qspec to propagate but the cluster sits on the
# quantized I/O boundary (e.g. a state-passthrough ``cat`` whose only
# neighbors are a uint8 model input -- skipped by
# _skip_shared_qspec_from_io -- and an input-state placeholder), initiate
# quantization from the global config rather than leaving the cluster in
# float. Otherwise such clusters fall off the integer delegate onto the
# CPU. Initiating from the global (internal) config keeps uint8 confined
# to the IO boundary.
if (
len(adjacent_qspecs) == 0
and touches_quantized_io
and self.global_config is not None
):
global_input_qspec = self.global_config.get_input_act_qspec()
if global_input_qspec is not None:
adjacent_qspecs = [global_input_qspec]

node_order = {node: index for index, node in enumerate(root_node.graph.nodes)}
ordered_nodes = sorted(shared_nodes, key=lambda node: node_order.get(node, 0))

Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backends/arm/quantizer/arm_quantizer.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -1220,6 +1220,10 @@ def set_global(
quantization_config, node_finder, self.pattern_matcher
)
self.global_config = quantization_config
# Let the shared-qspec pass initiate quantization from the global config
# for shared-op clusters that sit on the quantized I/O boundary but have
# no neighbor qspec to propagate (see SharedQspecQuantizer).
self.shared_qspec_quantizer.global_config = quantization_config
return self

def set_node_target(
Expand Down
58 changes: 53 additions & 5 deletions backends/arm/quantizer/arm_quantizer_utils.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -336,14 +336,22 @@ def annotate_match(
f"{node.name} is not expected to not have parameter tensors but found {[n.name for n in params]}, which may cause unexpected quantization annotations."
)

# Only ops in ``parameter_targets`` (conv/linear) have true weight and
# bias operands. For any other op, a parameter input is a constant
# activation operand and must be quantized with the input-activation
# qspec, not the weight qspec. Treating it as a weight breaks ops whose
# TOSA implementation requires both operands to share a dtype (e.g.
# add/sub), and silently demotes constants in int16 (16a8w) modules to
# int8 -- the weight qspec ``dtype`` differs from the activation dtype.
has_weight_and_bias = node.target in parameter_targets
for input_node in node.all_input_nodes:
if not has_float_output(input_node):
continue
if self.is_weight(input_node, params, model):
if has_weight_and_bias and self.is_weight(input_node, params, model):
input_qspec_map[input_node] = (
config.get_weight_qspec(node) if config else None
)
elif self.is_bias(input_node, params, model):
elif has_weight_and_bias and self.is_bias(input_node, params, model):
input_qspec_map[input_node] = (
config.get_bias_qspec(node) if config else None # type: ignore[assignment]
)
Expand DownExpand Up@@ -481,6 +489,10 @@ class SharedQspecQuantizer(Quantizer, QuantizerReporterUser):
def __init__(self, targets: Optional[list[Callable[..., object]]] = None) -> None:
super().__init__()
QuantizerReporterUser.__init__(self)
# Optional global config used to *initiate* quantization for shared-op
# clusters that sit on the quantized I/O boundary but have no neighbor
# qspec to propagate. Set by the composable quantizer's set_global().
self.global_config: Optional[QuantizationConfig] = None
if targets is None:
self.targets = self.SHARED_QSPEC_OPS_DEFAULT
self.support_config_path = (
Expand DownExpand Up@@ -552,10 +564,24 @@ def _append_input_qspec(
return
adjacent_qspecs.append(input_qspec)

def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any]]:
def _is_quantized_io_boundary(self, node: Node) -> bool:
"""Return True if ``node`` is a model input/output the quantizer
annotated.

Such a node sits on the quantized interface, but its qspec is often
filtered out of shared-cluster propagation -- a uint8 IO qspec is skipped
by ``_skip_shared_qspec_from_io``, and an input-state placeholder may
carry an annotation with no ``output_qspec``. Its presence still signals
that the cluster is on the quantized data path.

"""
return node.op in ("placeholder", "output") and self._is_annotated(node)

def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any], bool]:
shared_nodes = set()
bfs_queue = [root_node]
adjacent_qspecs: list[Any] = []
touches_quantized_io = False

while bfs_queue:
node = bfs_queue.pop(0)
Expand All@@ -564,12 +590,14 @@ def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any]]:
for input_node in node.all_input_nodes:
self._maybe_enqueue_shared_node(input_node, shared_nodes, bfs_queue)
self._append_output_qspec(input_node, adjacent_qspecs)
touches_quantized_io |= self._is_quantized_io_boundary(input_node)

for output_node in node.users.keys():
self._maybe_enqueue_shared_node(output_node, shared_nodes, bfs_queue)
self._append_input_qspec(output_node, node, adjacent_qspecs)
touches_quantized_io |= self._is_quantized_io_boundary(output_node)

return shared_nodes, adjacent_qspecs
return shared_nodes, adjacent_qspecs, touches_quantized_io

def _annotate_shared_cluster(self, root_node: Node) -> None:
if (
Expand All@@ -588,7 +616,27 @@ def _annotate_shared_cluster(self, root_node: Node) -> None:
)
return

shared_nodes, adjacent_qspecs = self._get_shared_clique(root_node)
shared_nodes, adjacent_qspecs, touches_quantized_io = self._get_shared_clique(
root_node
)

# If there is no neighbor qspec to propagate but the cluster sits on the
# quantized I/O boundary (e.g. a state-passthrough ``cat`` whose only
# neighbors are a uint8 model input -- skipped by
# _skip_shared_qspec_from_io -- and an input-state placeholder), initiate
# quantization from the global config rather than leaving the cluster in
# float. Otherwise such clusters fall off the integer delegate onto the
# CPU. Initiating from the global (internal) config keeps uint8 confined
# to the IO boundary.
if (
len(adjacent_qspecs) == 0
and touches_quantized_io
and self.global_config is not None
):
global_input_qspec = self.global_config.get_input_act_qspec()
if global_input_qspec is not None:
adjacent_qspecs = [global_input_qspec]

node_order = {node: index for index, node in enumerate(root_node.graph.nodes)}
ordered_nodes = sorted(shared_nodes, key=lambda node: node_order.get(node, 0))

Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backends/arm/quantizer/arm_quantizer.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -1220,6 +1220,10 @@ def set_global(
quantization_config, node_finder, self.pattern_matcher
)
self.global_config = quantization_config
# Let the shared-qspec pass initiate quantization from the global config
# for shared-op clusters that sit on the quantized I/O boundary but have
# no neighbor qspec to propagate (see SharedQspecQuantizer).
self.shared_qspec_quantizer.global_config = quantization_config
return self

def set_node_target(
Expand Down
58 changes: 53 additions & 5 deletions backends/arm/quantizer/arm_quantizer_utils.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -336,14 +336,22 @@ def annotate_match(
f"{node.name} is not expected to not have parameter tensors but found {[n.name for n in params]}, which may cause unexpected quantization annotations."
)

# Only ops in ``parameter_targets`` (conv/linear) have true weight and
# bias operands. For any other op, a parameter input is a constant
# activation operand and must be quantized with the input-activation
# qspec, not the weight qspec. Treating it as a weight breaks ops whose
# TOSA implementation requires both operands to share a dtype (e.g.
# add/sub), and silently demotes constants in int16 (16a8w) modules to
# int8 -- the weight qspec ``dtype`` differs from the activation dtype.
has_weight_and_bias = node.target in parameter_targets
for input_node in node.all_input_nodes:
if not has_float_output(input_node):
continue
if self.is_weight(input_node, params, model):
if has_weight_and_bias and self.is_weight(input_node, params, model):
input_qspec_map[input_node] = (
config.get_weight_qspec(node) if config else None
)
elif self.is_bias(input_node, params, model):
elif has_weight_and_bias and self.is_bias(input_node, params, model):
input_qspec_map[input_node] = (
config.get_bias_qspec(node) if config else None # type: ignore[assignment]
)
Expand DownExpand Up@@ -481,6 +489,10 @@ class SharedQspecQuantizer(Quantizer, QuantizerReporterUser):
def __init__(self, targets: Optional[list[Callable[..., object]]] = None) -> None:
super().__init__()
QuantizerReporterUser.__init__(self)
# Optional global config used to *initiate* quantization for shared-op
# clusters that sit on the quantized I/O boundary but have no neighbor
# qspec to propagate. Set by the composable quantizer's set_global().
self.global_config: Optional[QuantizationConfig] = None
if targets is None:
self.targets = self.SHARED_QSPEC_OPS_DEFAULT
self.support_config_path = (
Expand DownExpand Up@@ -552,10 +564,24 @@ def _append_input_qspec(
return
adjacent_qspecs.append(input_qspec)

def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any]]:
def _is_quantized_io_boundary(self, node: Node) -> bool:
"""Return True if ``node`` is a model input/output the quantizer
annotated.

Such a node sits on the quantized interface, but its qspec is often
filtered out of shared-cluster propagation -- a uint8 IO qspec is skipped
by ``_skip_shared_qspec_from_io``, and an input-state placeholder may
carry an annotation with no ``output_qspec``. Its presence still signals
that the cluster is on the quantized data path.

"""
return node.op in ("placeholder", "output") and self._is_annotated(node)

def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any], bool]:
shared_nodes = set()
bfs_queue = [root_node]
adjacent_qspecs: list[Any] = []
touches_quantized_io = False

while bfs_queue:
node = bfs_queue.pop(0)
Expand All@@ -564,12 +590,14 @@ def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any]]:
for input_node in node.all_input_nodes:
self._maybe_enqueue_shared_node(input_node, shared_nodes, bfs_queue)
self._append_output_qspec(input_node, adjacent_qspecs)
touches_quantized_io |= self._is_quantized_io_boundary(input_node)

for output_node in node.users.keys():
self._maybe_enqueue_shared_node(output_node, shared_nodes, bfs_queue)
self._append_input_qspec(output_node, node, adjacent_qspecs)
touches_quantized_io |= self._is_quantized_io_boundary(output_node)

return shared_nodes, adjacent_qspecs
return shared_nodes, adjacent_qspecs, touches_quantized_io

def _annotate_shared_cluster(self, root_node: Node) -> None:
if (
Expand All@@ -588,7 +616,27 @@ def _annotate_shared_cluster(self, root_node: Node) -> None:
)
return

shared_nodes, adjacent_qspecs = self._get_shared_clique(root_node)
shared_nodes, adjacent_qspecs, touches_quantized_io = self._get_shared_clique(
root_node
)

# If there is no neighbor qspec to propagate but the cluster sits on the
# quantized I/O boundary (e.g. a state-passthrough ``cat`` whose only
# neighbors are a uint8 model input -- skipped by
# _skip_shared_qspec_from_io -- and an input-state placeholder), initiate
# quantization from the global config rather than leaving the cluster in
# float. Otherwise such clusters fall off the integer delegate onto the
# CPU. Initiating from the global (internal) config keeps uint8 confined
# to the IO boundary.
if (
len(adjacent_qspecs) == 0
and touches_quantized_io
and self.global_config is not None
):
global_input_qspec = self.global_config.get_input_act_qspec()
if global_input_qspec is not None:
adjacent_qspecs = [global_input_qspec]

node_order = {node: index for index, node in enumerate(root_node.graph.nodes)}
ordered_nodes = sorted(shared_nodes, key=lambda node: node_order.get(node, 0))

Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backends/arm/quantizer/arm_quantizer.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -1220,6 +1220,10 @@ def set_global(
quantization_config, node_finder, self.pattern_matcher
)
self.global_config = quantization_config
# Let the shared-qspec pass initiate quantization from the global config
# for shared-op clusters that sit on the quantized I/O boundary but have
# no neighbor qspec to propagate (see SharedQspecQuantizer).
self.shared_qspec_quantizer.global_config = quantization_config
return self

def set_node_target(
Expand Down
58 changes: 53 additions & 5 deletions backends/arm/quantizer/arm_quantizer_utils.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -336,14 +336,22 @@ def annotate_match(
f"{node.name} is not expected to not have parameter tensors but found {[n.name for n in params]}, which may cause unexpected quantization annotations."
)

# Only ops in ``parameter_targets`` (conv/linear) have true weight and
# bias operands. For any other op, a parameter input is a constant
# activation operand and must be quantized with the input-activation
# qspec, not the weight qspec. Treating it as a weight breaks ops whose
# TOSA implementation requires both operands to share a dtype (e.g.
# add/sub), and silently demotes constants in int16 (16a8w) modules to
# int8 -- the weight qspec ``dtype`` differs from the activation dtype.
has_weight_and_bias = node.target in parameter_targets
for input_node in node.all_input_nodes:
if not has_float_output(input_node):
continue
if self.is_weight(input_node, params, model):
if has_weight_and_bias and self.is_weight(input_node, params, model):
input_qspec_map[input_node] = (
config.get_weight_qspec(node) if config else None
)
elif self.is_bias(input_node, params, model):
elif has_weight_and_bias and self.is_bias(input_node, params, model):
input_qspec_map[input_node] = (
config.get_bias_qspec(node) if config else None # type: ignore[assignment]
)
Expand DownExpand Up@@ -481,6 +489,10 @@ class SharedQspecQuantizer(Quantizer, QuantizerReporterUser):
def __init__(self, targets: Optional[list[Callable[..., object]]] = None) -> None:
super().__init__()
QuantizerReporterUser.__init__(self)
# Optional global config used to *initiate* quantization for shared-op
# clusters that sit on the quantized I/O boundary but have no neighbor
# qspec to propagate. Set by the composable quantizer's set_global().
self.global_config: Optional[QuantizationConfig] = None
if targets is None:
self.targets = self.SHARED_QSPEC_OPS_DEFAULT
self.support_config_path = (
Expand DownExpand Up@@ -552,10 +564,24 @@ def _append_input_qspec(
return
adjacent_qspecs.append(input_qspec)

def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any]]:
def _is_quantized_io_boundary(self, node: Node) -> bool:
"""Return True if ``node`` is a model input/output the quantizer
annotated.

Such a node sits on the quantized interface, but its qspec is often
filtered out of shared-cluster propagation -- a uint8 IO qspec is skipped
by ``_skip_shared_qspec_from_io``, and an input-state placeholder may
carry an annotation with no ``output_qspec``. Its presence still signals
that the cluster is on the quantized data path.

"""
return node.op in ("placeholder", "output") and self._is_annotated(node)

def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any], bool]:
shared_nodes = set()
bfs_queue = [root_node]
adjacent_qspecs: list[Any] = []
touches_quantized_io = False

while bfs_queue:
node = bfs_queue.pop(0)
Expand All@@ -564,12 +590,14 @@ def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any]]:
for input_node in node.all_input_nodes:
self._maybe_enqueue_shared_node(input_node, shared_nodes, bfs_queue)
self._append_output_qspec(input_node, adjacent_qspecs)
touches_quantized_io |= self._is_quantized_io_boundary(input_node)

for output_node in node.users.keys():
self._maybe_enqueue_shared_node(output_node, shared_nodes, bfs_queue)
self._append_input_qspec(output_node, node, adjacent_qspecs)
touches_quantized_io |= self._is_quantized_io_boundary(output_node)

return shared_nodes, adjacent_qspecs
return shared_nodes, adjacent_qspecs, touches_quantized_io

def _annotate_shared_cluster(self, root_node: Node) -> None:
if (
Expand All@@ -588,7 +616,27 @@ def _annotate_shared_cluster(self, root_node: Node) -> None:
)
return

shared_nodes, adjacent_qspecs = self._get_shared_clique(root_node)
shared_nodes, adjacent_qspecs, touches_quantized_io = self._get_shared_clique(
root_node
)

# If there is no neighbor qspec to propagate but the cluster sits on the
# quantized I/O boundary (e.g. a state-passthrough ``cat`` whose only
# neighbors are a uint8 model input -- skipped by
# _skip_shared_qspec_from_io -- and an input-state placeholder), initiate
# quantization from the global config rather than leaving the cluster in
# float. Otherwise such clusters fall off the integer delegate onto the
# CPU. Initiating from the global (internal) config keeps uint8 confined
# to the IO boundary.
if (
len(adjacent_qspecs) == 0
and touches_quantized_io
and self.global_config is not None
):
global_input_qspec = self.global_config.get_input_act_qspec()
if global_input_qspec is not None:
adjacent_qspecs = [global_input_qspec]

node_order = {node: index for index, node in enumerate(root_node.graph.nodes)}
ordered_nodes = sorted(shared_nodes, key=lambda node: node_order.get(node, 0))

Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backends/arm/quantizer/arm_quantizer.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -1220,6 +1220,10 @@ def set_global(
quantization_config, node_finder, self.pattern_matcher
)
self.global_config = quantization_config
# Let the shared-qspec pass initiate quantization from the global config
# for shared-op clusters that sit on the quantized I/O boundary but have
# no neighbor qspec to propagate (see SharedQspecQuantizer).
self.shared_qspec_quantizer.global_config = quantization_config
return self

def set_node_target(
Expand Down
58 changes: 53 additions & 5 deletions backends/arm/quantizer/arm_quantizer_utils.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -336,14 +336,22 @@ def annotate_match(
f"{node.name} is not expected to not have parameter tensors but found {[n.name for n in params]}, which may cause unexpected quantization annotations."
)

# Only ops in ``parameter_targets`` (conv/linear) have true weight and
# bias operands. For any other op, a parameter input is a constant
# activation operand and must be quantized with the input-activation
# qspec, not the weight qspec. Treating it as a weight breaks ops whose
# TOSA implementation requires both operands to share a dtype (e.g.
# add/sub), and silently demotes constants in int16 (16a8w) modules to
# int8 -- the weight qspec ``dtype`` differs from the activation dtype.
has_weight_and_bias = node.target in parameter_targets
for input_node in node.all_input_nodes:
if not has_float_output(input_node):
continue
if self.is_weight(input_node, params, model):
if has_weight_and_bias and self.is_weight(input_node, params, model):
input_qspec_map[input_node] = (
config.get_weight_qspec(node) if config else None
)
elif self.is_bias(input_node, params, model):
elif has_weight_and_bias and self.is_bias(input_node, params, model):
input_qspec_map[input_node] = (
config.get_bias_qspec(node) if config else None # type: ignore[assignment]
)
Expand DownExpand Up@@ -481,6 +489,10 @@ class SharedQspecQuantizer(Quantizer, QuantizerReporterUser):
def __init__(self, targets: Optional[list[Callable[..., object]]] = None) -> None:
super().__init__()
QuantizerReporterUser.__init__(self)
# Optional global config used to *initiate* quantization for shared-op
# clusters that sit on the quantized I/O boundary but have no neighbor
# qspec to propagate. Set by the composable quantizer's set_global().
self.global_config: Optional[QuantizationConfig] = None
if targets is None:
self.targets = self.SHARED_QSPEC_OPS_DEFAULT
self.support_config_path = (
Expand DownExpand Up@@ -552,10 +564,24 @@ def _append_input_qspec(
return
adjacent_qspecs.append(input_qspec)

def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any]]:
def _is_quantized_io_boundary(self, node: Node) -> bool:
"""Return True if ``node`` is a model input/output the quantizer
annotated.

Such a node sits on the quantized interface, but its qspec is often
filtered out of shared-cluster propagation -- a uint8 IO qspec is skipped
by ``_skip_shared_qspec_from_io``, and an input-state placeholder may
carry an annotation with no ``output_qspec``. Its presence still signals
that the cluster is on the quantized data path.

"""
return node.op in ("placeholder", "output") and self._is_annotated(node)

def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any], bool]:
shared_nodes = set()
bfs_queue = [root_node]
adjacent_qspecs: list[Any] = []
touches_quantized_io = False

while bfs_queue:
node = bfs_queue.pop(0)
Expand All@@ -564,12 +590,14 @@ def _get_shared_clique(self, root_node: Node) -> tuple[set[Node], list[Any]]:
for input_node in node.all_input_nodes:
self._maybe_enqueue_shared_node(input_node, shared_nodes, bfs_queue)
self._append_output_qspec(input_node, adjacent_qspecs)
touches_quantized_io |= self._is_quantized_io_boundary(input_node)

for output_node in node.users.keys():
self._maybe_enqueue_shared_node(output_node, shared_nodes, bfs_queue)
self._append_input_qspec(output_node, node, adjacent_qspecs)
touches_quantized_io |= self._is_quantized_io_boundary(output_node)

return shared_nodes, adjacent_qspecs
return shared_nodes, adjacent_qspecs, touches_quantized_io

def _annotate_shared_cluster(self, root_node: Node) -> None:
if (
Expand All@@ -588,7 +616,27 @@ def _annotate_shared_cluster(self, root_node: Node) -> None:
)
return

shared_nodes, adjacent_qspecs = self._get_shared_clique(root_node)
shared_nodes, adjacent_qspecs, touches_quantized_io = self._get_shared_clique(
root_node
)

# If there is no neighbor qspec to propagate but the cluster sits on the
# quantized I/O boundary (e.g. a state-passthrough ``cat`` whose only
# neighbors are a uint8 model input -- skipped by
# _skip_shared_qspec_from_io -- and an input-state placeholder), initiate
# quantization from the global config rather than leaving the cluster in
# float. Otherwise such clusters fall off the integer delegate onto the
# CPU. Initiating from the global (internal) config keeps uint8 confined
# to the IO boundary.
if (
len(adjacent_qspecs) == 0
and touches_quantized_io
and self.global_config is not None
):
global_input_qspec = self.global_config.get_input_act_qspec()
if global_input_qspec is not None:
adjacent_qspecs = [global_input_qspec]

node_order = {node: index for index, node in enumerate(root_node.graph.nodes)}
ordered_nodes = sorted(shared_nodes, key=lambda node: node_order.get(node, 0))

Expand Down
Loading