add-torch-shapes-example

작성자: facebook

Pyrefly의 형상 추적 예제 코퍼스인 tensor-shapes/pyrefly-torch-stubs/examples에 새로운 PyTorch 모델을 추가할 때 사용합니다. 즉, 모델을 임포트하여...

npx skills add https://github.com/facebook/pyrefly --skill add-torch-shapes-example

You are importing a PyTorch model into Pyrefly's example corpus at tensor-shapes/pyrefly-torch-stubs/examples/. This is the contribution case the porting skill describes: these ports are tested reference material that others read to learn the patterns, so produce its fuller deliverable — paste every artifact (audit table, per-local reveal_type dumps, typed-interface receipts, exhaustive assert_type coverage, completion report) in full, not just the annotated model.

Why these ports matter. They demonstrate what happens when you write a real PyTorch model with tensor shape types. Record the upstream repository and revision, exact files or dependency closure, concrete configuration, entry points, and train/eval/cache/export modes included. "Complete" means complete inside that declared boundary; list any omitted wrapper or mode rather than calling a representative core the full upstream model.

Start from evidence, not a blank page. Before editing, skim two or three existing examples with the closest architecture and mine the upstream source for shape comments, docstrings, reshape/einsum equations, runtime assertions, and tests. Treat that evidence as a hypothesis to verify with Pyrefly, not text to copy. The existing ports demonstrate that substantial real models normally reach useful shape coverage after a few checker-guided iterations.

Improving the stubs is the point, not a side quest. First distinguish a true stub gap from an unavailable overlay symbol, Any, a declared gradual return, third-party code, or unrepresentable dynamic construction. Fix genuine general stub gaps in the corpus case rather than hiding them in the model. A corpus port may retain a narrow precise cast, typed interface, or gradual boundary for heterogeneous containers, dynamic factories, mutable caches, or untyped external backends. Preserve every known public dimension and document the boundary. Propose, but do not perform, a runtime rewrite unless the user separately requests it.

1. Run the port

Do the actual porting by reading and following the add-shape-types-to-torch-model skill's SKILL.md (in tensor-shapes/skills/add-shape-types-to-torch-model/) end to end — its gated workflow (pre-flight gates → per-module loop → verification) is the algorithm.

The general skill has two setup choices; for corpus work both are already resolved, so do not stop to ask: use the Buck check below, and treat stub improvements as in scope. Produce all of the corpus artifacts it requests.

2. Place the file

Write the port at tensor-shapes/pyrefly-torch-stubs/examples/<model>.py. Every class, function, method, entry point, configuration, and mode inside the declared upstream boundary belongs in the port. Do not silently shrink that boundary when a difficult construct appears.

3. Verify (the fbsource commands)

The porting skill's verification phase tells you to run verify_port.sh and the actual Pyrefly check. Run these commands from the fbcode/pyrefly checkout root. First ensure the shared tensor-shapes virtual environment exists; add --fwdproxy when the host needs it:

python3 tensor-shapes/bootstrap_venv.py
buck build fbcode//pyrefly/tensor-shapes:torch-stubs-search-path
SEARCH_ROOT="$(buck targets --show-output fbcode//pyrefly/tensor-shapes:torch-stubs-search-path | awk '{print $2}')"
VENV="${TENSOR_SHAPES_VENV:-$HOME/.tensor-shapes-venv}"
SITE="$("$VENV/bin/python" -c 'import site; print(site.getsitepackages()[0])')"
buck run fbcode//pyrefly:pyrefly -- check --config /dev/null \
  --python-version 3.13 --search-path "$SEARCH_ROOT" \
  --site-package-path "$SITE" \
  tensor-shapes/pyrefly-torch-stubs/examples/<model>.py

If the model imports einops, also pass --search-path tensor-shapes/pyrefly-einops-stubs; otherwise an einops call can silently appear to preserve its input shape. The result must be 0 errors, with no leftover reveal_type.

Then run the corpus test target so the new example is covered by CI and checked with the real Torch fallback modules:

python3 tensor-shapes/pyrefly-torch-stubs/run_pyrefly.py --buck --suite torch-examples

If you hit a wrong or missing shape

When shape precision is missing, first distinguish among an unavailable symbol in the partial overlay, Any, a declared gradual Tensor, a third-party boundary, and a true stub-signature gap. Add or refine a general stub when that is the right fix. A corpus port may retain a documented boundary for unrepresentable dynamic construction; it should not hide an easily fixable stub gap.

A wrong shape (Pyrefly computes a concrete shape that's incorrect) or a missing shape that can't be expressed by a stub signature alone is a shape-DSL change: see the modify-shaped-array-dsl skill. That skill insists on unit-testing the DSL logic, not just relying on this example to exercise it. Don't reach for the DSL for shapes a stub signature could express.

facebook의 다른 스킬

gc-safe-coding
facebook
전체 설명과 근거는 doc/GCSafeCoding.md를 참조하십시오.
app-review-prep
facebook
Meta 앱을 App Review용으로 준비합니다 — 현재 상태, 미해결 요구 사항, 부여된 권한, 제출 내역을 확인합니다. 앱을 제출하기 전에 사용하세요…
api-health
facebook
Meta 앱의 API 상태를 모니터링합니다 — 비율 제한, 호출량, API 지원 중단 여부를 확인합니다. 트래픽 제한을 진단하거나, 용량을 계획하거나, API 버전 변경에 대비하는 데 사용합니다…
debug-webhooks
facebook
Meta 앱의 웹훅 문제를 해결합니다 — 활성 구독을 검사하고, 잘못된 구성을 식별하며, 테스트 페이로드를 전송하여 전달을 확인합니다. 다음과 같은 경우에 사용하세요…
api-integration
facebook
개발자가 Meta API 통합을 처음부터 설정하도록 안내합니다 — 적절한 API를 찾아내고, 설정 가이드, 인증 요구 사항 등을 가져옵니다…
webhook-setup
facebook
Meta 앱용 웹훅을 처음부터 끝까지 설정하세요 — 사용 가능한 주제를 탐색하고, 필드를 구독하고, 테스트 페이로드로 검증합니다. 웹훅을 구성할 때 사용하세요…
test-ui
facebook
iwsdk CLI를 사용하여 포크 예제에 대해 Test UI 시스템(PanelUI, ScreenSpace)을 테스트합니다.
flags
facebook
React 릴리스 채널 간 기능 플래그 상태를 검사하고 비교합니다. 모든 채널(www, www-modern, canary, next, experimental, rn 변형)의 플래그를 보거나 --diff로 특정 채널을 비교합니다. 출력 형식은 기본 테이블 보기, CSV 내보내기, 정리 상태 그룹화를 포함합니다. 플래그 상태는 기호로 표시됩니다: 활성화(✅), 비활성화(❌), 변형 테스트(🧪), 프로파일링 전용(📊). 일반적인 실수: __VARIANT__ 플래그는 www에서 두 상태 모두 테스트되며, --diff를 사용하여 의미 있는 차이를 찾습니다...