layer-scan 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- layer_scan-0.1.0/.github/ISSUE_TEMPLATE/bug_report.yml +57 -0
- layer_scan-0.1.0/.github/ISSUE_TEMPLATE/feature_request.yml +23 -0
- layer_scan-0.1.0/.github/pull_request_template.md +23 -0
- layer_scan-0.1.0/.github/workflows/ci.yml +48 -0
- layer_scan-0.1.0/.github/workflows/release.yml +34 -0
- layer_scan-0.1.0/.gitignore +18 -0
- layer_scan-0.1.0/CHANGELOG.md +23 -0
- layer_scan-0.1.0/CODE_OF_CONDUCT.md +40 -0
- layer_scan-0.1.0/CONTRIBUTING.md +64 -0
- layer_scan-0.1.0/LICENSE +21 -0
- layer_scan-0.1.0/NOTICE +14 -0
- layer_scan-0.1.0/PKG-INFO +347 -0
- layer_scan-0.1.0/README.md +307 -0
- layer_scan-0.1.0/examples/custom_probe_example.py +104 -0
- layer_scan-0.1.0/examples/scan_qwen2_72b.py +99 -0
- layer_scan-0.1.0/llms.txt +16 -0
- layer_scan-0.1.0/pyproject.toml +81 -0
- layer_scan-0.1.0/src/layer_scan/__init__.py +3 -0
- layer_scan-0.1.0/src/layer_scan/backends/__init__.py +9 -0
- layer_scan-0.1.0/src/layer_scan/backends/base.py +51 -0
- layer_scan-0.1.0/src/layer_scan/backends/exllamav2.py +224 -0
- layer_scan-0.1.0/src/layer_scan/backends/transformers_backend.py +254 -0
- layer_scan-0.1.0/src/layer_scan/cli.py +234 -0
- layer_scan-0.1.0/src/layer_scan/config.py +112 -0
- layer_scan-0.1.0/src/layer_scan/export.py +63 -0
- layer_scan-0.1.0/src/layer_scan/heatmap.py +234 -0
- layer_scan-0.1.0/src/layer_scan/probes/__init__.py +9 -0
- layer_scan-0.1.0/src/layer_scan/probes/base.py +93 -0
- layer_scan-0.1.0/src/layer_scan/probes/custom.py +77 -0
- layer_scan-0.1.0/src/layer_scan/probes/eq_probe.py +162 -0
- layer_scan-0.1.0/src/layer_scan/probes/json_probe.py +179 -0
- layer_scan-0.1.0/src/layer_scan/probes/math_probe.py +190 -0
- layer_scan-0.1.0/src/layer_scan/scanner.py +249 -0
- layer_scan-0.1.0/src/layer_scan/scoring.py +150 -0
- layer_scan-0.1.0/tests/__init__.py +0 -0
- layer_scan-0.1.0/tests/conftest.py +128 -0
- layer_scan-0.1.0/tests/test_backends.py +345 -0
- layer_scan-0.1.0/tests/test_boundaries.py +163 -0
- layer_scan-0.1.0/tests/test_cli_blackbox.py +132 -0
- layer_scan-0.1.0/tests/test_config.py +102 -0
- layer_scan-0.1.0/tests/test_heatmap.py +168 -0
- layer_scan-0.1.0/tests/test_probes.py +140 -0
- layer_scan-0.1.0/tests/test_real_scenarios.py +238 -0
- layer_scan-0.1.0/tests/test_scanner.py +118 -0
- layer_scan-0.1.0/tests/test_scoring.py +114 -0
- layer_scan-0.1.0/tests/test_smoke.py +53 -0
- layer_scan-0.1.0/tests/test_stress.py +126 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
name: Bug Report
|
|
2
|
+
description: Report a bug in layer-scan
|
|
3
|
+
labels: [bug]
|
|
4
|
+
body:
|
|
5
|
+
- type: input
|
|
6
|
+
id: version
|
|
7
|
+
attributes:
|
|
8
|
+
label: layer-scan version
|
|
9
|
+
description: Output of `layer-scan version`
|
|
10
|
+
placeholder: "0.1.0"
|
|
11
|
+
validations:
|
|
12
|
+
required: true
|
|
13
|
+
- type: input
|
|
14
|
+
id: python
|
|
15
|
+
attributes:
|
|
16
|
+
label: Python version
|
|
17
|
+
description: Output of `python --version`
|
|
18
|
+
placeholder: "3.12.0"
|
|
19
|
+
validations:
|
|
20
|
+
required: true
|
|
21
|
+
- type: input
|
|
22
|
+
id: os
|
|
23
|
+
attributes:
|
|
24
|
+
label: Operating System
|
|
25
|
+
placeholder: "Ubuntu 22.04 / Windows 11 / macOS 14"
|
|
26
|
+
validations:
|
|
27
|
+
required: true
|
|
28
|
+
- type: textarea
|
|
29
|
+
id: steps
|
|
30
|
+
attributes:
|
|
31
|
+
label: Steps to reproduce
|
|
32
|
+
description: Minimal steps to trigger the bug
|
|
33
|
+
placeholder: |
|
|
34
|
+
1. Install layer-scan
|
|
35
|
+
2. Run `layer-scan scan --model ...`
|
|
36
|
+
3. See error
|
|
37
|
+
validations:
|
|
38
|
+
required: true
|
|
39
|
+
- type: textarea
|
|
40
|
+
id: expected
|
|
41
|
+
attributes:
|
|
42
|
+
label: Expected behavior
|
|
43
|
+
description: What you expected to happen
|
|
44
|
+
validations:
|
|
45
|
+
required: true
|
|
46
|
+
- type: textarea
|
|
47
|
+
id: actual
|
|
48
|
+
attributes:
|
|
49
|
+
label: Actual behavior
|
|
50
|
+
description: What actually happened (include error messages / tracebacks)
|
|
51
|
+
validations:
|
|
52
|
+
required: true
|
|
53
|
+
- type: textarea
|
|
54
|
+
id: extra
|
|
55
|
+
attributes:
|
|
56
|
+
label: Additional context
|
|
57
|
+
description: Model name, backend, GPU info, or anything else relevant
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: Feature Request
|
|
2
|
+
description: Suggest a new feature or improvement
|
|
3
|
+
labels: [enhancement]
|
|
4
|
+
body:
|
|
5
|
+
- type: textarea
|
|
6
|
+
id: usecase
|
|
7
|
+
attributes:
|
|
8
|
+
label: Use case
|
|
9
|
+
description: What problem does this solve? Who benefits?
|
|
10
|
+
validations:
|
|
11
|
+
required: true
|
|
12
|
+
- type: textarea
|
|
13
|
+
id: proposal
|
|
14
|
+
attributes:
|
|
15
|
+
label: Proposed solution
|
|
16
|
+
description: How should it work? Include CLI examples if applicable.
|
|
17
|
+
validations:
|
|
18
|
+
required: true
|
|
19
|
+
- type: textarea
|
|
20
|
+
id: alternatives
|
|
21
|
+
attributes:
|
|
22
|
+
label: Alternatives considered
|
|
23
|
+
description: Other approaches you considered and why they don't work
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
## Type
|
|
2
|
+
|
|
3
|
+
- [ ] Bug fix
|
|
4
|
+
- [ ] New feature
|
|
5
|
+
- [ ] Refactoring
|
|
6
|
+
- [ ] Documentation
|
|
7
|
+
- [ ] CI/CD
|
|
8
|
+
|
|
9
|
+
## Summary
|
|
10
|
+
|
|
11
|
+
<!-- Brief description of what this PR does -->
|
|
12
|
+
|
|
13
|
+
## Test plan
|
|
14
|
+
|
|
15
|
+
- [ ] New tests added / existing tests updated
|
|
16
|
+
- [ ] `pytest -m smoke` passes
|
|
17
|
+
- [ ] `pytest -m "not slow"` passes
|
|
18
|
+
- [ ] `ruff check .` passes
|
|
19
|
+
|
|
20
|
+
## Documentation
|
|
21
|
+
|
|
22
|
+
- [ ] README updated (if user-facing change)
|
|
23
|
+
- [ ] CHANGELOG updated
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
lint:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
- uses: actions/setup-python@v5
|
|
15
|
+
with:
|
|
16
|
+
python-version: "3.12"
|
|
17
|
+
- run: pip install ruff
|
|
18
|
+
- run: ruff check .
|
|
19
|
+
|
|
20
|
+
smoke:
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
needs: lint
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v4
|
|
25
|
+
- uses: actions/setup-python@v5
|
|
26
|
+
with:
|
|
27
|
+
python-version: "3.12"
|
|
28
|
+
- run: pip install -e ".[dev]"
|
|
29
|
+
- run: pytest -m smoke -v
|
|
30
|
+
|
|
31
|
+
test:
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
needs: smoke
|
|
34
|
+
strategy:
|
|
35
|
+
matrix:
|
|
36
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
37
|
+
steps:
|
|
38
|
+
- uses: actions/checkout@v4
|
|
39
|
+
- uses: actions/setup-python@v5
|
|
40
|
+
with:
|
|
41
|
+
python-version: ${{ matrix.python-version }}
|
|
42
|
+
- run: pip install -e ".[dev]"
|
|
43
|
+
- run: pytest --cov --cov-report=xml -m "not slow" -v
|
|
44
|
+
- uses: codecov/codecov-action@v4
|
|
45
|
+
if: matrix.python-version == '3.12'
|
|
46
|
+
with:
|
|
47
|
+
file: ./coverage.xml
|
|
48
|
+
fail_ci_if_error: false
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags: ["v*"]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
id-token: write
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: actions/setup-python@v5
|
|
16
|
+
with:
|
|
17
|
+
python-version: "3.12"
|
|
18
|
+
- run: pip install hatch
|
|
19
|
+
- run: hatch build
|
|
20
|
+
- uses: actions/upload-artifact@v4
|
|
21
|
+
with:
|
|
22
|
+
name: dist
|
|
23
|
+
path: dist/
|
|
24
|
+
|
|
25
|
+
publish:
|
|
26
|
+
runs-on: ubuntu-latest
|
|
27
|
+
needs: build
|
|
28
|
+
environment: pypi
|
|
29
|
+
steps:
|
|
30
|
+
- uses: actions/download-artifact@v4
|
|
31
|
+
with:
|
|
32
|
+
name: dist
|
|
33
|
+
path: dist/
|
|
34
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-03-11
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Core scanning engine with configurable (i, j) layer duplication
|
|
13
|
+
- Logit distribution scoring (deterministic, no sampling)
|
|
14
|
+
- Three built-in probes: math, eq (emotional intelligence), json (format compliance)
|
|
15
|
+
- Custom probe support via JSON files
|
|
16
|
+
- Two inference backends: HuggingFace Transformers and ExLlamaV2
|
|
17
|
+
- Interactive Plotly HTML heatmap visualization
|
|
18
|
+
- mergekit passthrough YAML export (`--export-mergekit`)
|
|
19
|
+
- Sparse-first two-pass scanning (`--sparse-first`)
|
|
20
|
+
- CLI with `scan`, `probes`, and `version` commands
|
|
21
|
+
- Input validation for ScanConfig parameters
|
|
22
|
+
- Comprehensive test suite (smoke, black-box, white-box, boundary, stress)
|
|
23
|
+
- CI/CD with GitHub Actions (lint, test, PyPI publish)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
|
10
|
+
identity and orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to a positive environment:
|
|
15
|
+
|
|
16
|
+
* Using welcoming and inclusive language
|
|
17
|
+
* Being respectful of differing viewpoints and experiences
|
|
18
|
+
* Gracefully accepting constructive criticism
|
|
19
|
+
* Focusing on what is best for the community
|
|
20
|
+
* Showing empathy towards other community members
|
|
21
|
+
|
|
22
|
+
Examples of unacceptable behavior:
|
|
23
|
+
|
|
24
|
+
* The use of sexualized language or imagery, and sexual attention or advances
|
|
25
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
26
|
+
* Public or private harassment
|
|
27
|
+
* Publishing others' private information without explicit permission
|
|
28
|
+
* Other conduct which could reasonably be considered inappropriate
|
|
29
|
+
|
|
30
|
+
## Enforcement
|
|
31
|
+
|
|
32
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
33
|
+
reported to the project maintainers. All complaints will be reviewed and
|
|
34
|
+
investigated promptly and fairly.
|
|
35
|
+
|
|
36
|
+
## Attribution
|
|
37
|
+
|
|
38
|
+
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org),
|
|
39
|
+
version 2.1, available at
|
|
40
|
+
https://www.contributor-covenant.org/version/2/1/code_of_conduct.html.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Contributing to layer-scan
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing!
|
|
4
|
+
|
|
5
|
+
## Development setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
git clone https://github.com/layer-scan/layer-scan.git
|
|
9
|
+
cd layer-scan
|
|
10
|
+
python -m venv .venv && source .venv/bin/activate
|
|
11
|
+
pip install -e ".[dev]"
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Running tests
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# Smoke tests (fast, <10s)
|
|
18
|
+
pytest -m smoke
|
|
19
|
+
|
|
20
|
+
# All tests except slow
|
|
21
|
+
pytest -m "not slow"
|
|
22
|
+
|
|
23
|
+
# Full suite including stress tests
|
|
24
|
+
pytest
|
|
25
|
+
|
|
26
|
+
# With coverage
|
|
27
|
+
pytest --cov --cov-report=term-missing
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Code style
|
|
31
|
+
|
|
32
|
+
We use [Ruff](https://docs.astral.sh/ruff/) for linting and formatting:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
ruff check .
|
|
36
|
+
ruff format .
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Configuration is in `pyproject.toml` (target: Python 3.10, line length: 100).
|
|
40
|
+
|
|
41
|
+
## Pull request process
|
|
42
|
+
|
|
43
|
+
1. Fork the repo and create a feature branch
|
|
44
|
+
2. Write tests first (TDD encouraged)
|
|
45
|
+
3. Ensure `ruff check .` passes
|
|
46
|
+
4. Ensure `pytest -m "not slow"` passes
|
|
47
|
+
5. Update CHANGELOG.md under `[Unreleased]`
|
|
48
|
+
6. Open a PR with the provided template
|
|
49
|
+
|
|
50
|
+
## Adding a new probe
|
|
51
|
+
|
|
52
|
+
1. Create `src/layer_scan/probes/your_probe.py`
|
|
53
|
+
2. Subclass `Probe` from `layer_scan.probes.base`
|
|
54
|
+
3. Implement `name`, `description`, `get_samples()`, `get_score_token_ids()`
|
|
55
|
+
4. Register in `cli.py` `_load_probe()` builtin_probes dict
|
|
56
|
+
5. Add tests in `tests/test_probes.py`
|
|
57
|
+
|
|
58
|
+
## Adding a new backend
|
|
59
|
+
|
|
60
|
+
1. Create `src/layer_scan/backends/your_backend.py`
|
|
61
|
+
2. Subclass `Backend` from `layer_scan.backends.base`
|
|
62
|
+
3. Implement `load()`, `get_total_layers()`, `get_tokenizer()`, `forward_with_duplication()`
|
|
63
|
+
4. Register in `cli.py` `_load_backend()`
|
|
64
|
+
5. Add tests in `tests/test_backends.py`
|
layer_scan-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 XXO47OXX
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
layer_scan-0.1.0/NOTICE
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Copyright (c) 2026 XXO47OXX
|
|
2
|
+
Licensed under MIT License
|
|
3
|
+
|
|
4
|
+
Original Design & First Published: 2026-03-11
|
|
5
|
+
Provenance Identifier: LS-XXO47OXX-a3f7c9e1-2026
|
|
6
|
+
|
|
7
|
+
This project is the original implementation of:
|
|
8
|
+
- Logit distribution scoring for layer duplication evaluation (no sampling, deterministic)
|
|
9
|
+
- Full (i,j) configuration space automatic scanning for RYS-style layer duplication
|
|
10
|
+
- Task-specific probe system with cross-probe heatmap comparison
|
|
11
|
+
- One-click mergekit passthrough YAML export from scan results
|
|
12
|
+
|
|
13
|
+
If you fork or create derivative works, please retain this NOTICE file
|
|
14
|
+
and attribute the original repository: https://github.com/XXO47OXX/layer-scan
|