# TensorFlow vs PyTorch: source lines of code compared

The TensorFlow vs PyTorch comparison on OctoCounts shows side-by-side source line counts for tensorflow/tensorflow and pytorch/pytorch, counted with the same engine and analysis options on the dates shown in the methodology line: files, total lines, code lines, comment lines, blank lines, and per-language totals, pinned to the exact commits listed below.

As of 2026-09-21, tensorflow/tensorflow contains 6,799,243 total lines (5,100,331 code) across 24,152 files, while pytorch/pytorch contains 3,276,403 total lines (2,563,680 code) across 8,757 files as of 2026-09-21. tensorflow/tensorflow is about 2.0x the size of pytorch/pytorch by code lines. Code size is not code quality: a larger count only means more source material, not a better or worse project.

| Metric | [tensorflow/tensorflow](https://octocounts.com/github/tensorflow/tensorflow) | [pytorch/pytorch](https://octocounts.com/github/pytorch/pytorch) |
| --- | ---: | ---: |
| Files | 24,152 | 8,757 |
| Total lines | 6,799,243 | 3,276,403 |
| Code lines | 5,100,331 | 2,563,680 |
| Comment lines | 952,216 | 341,378 |
| Blank lines | 746,696 | 371,345 |
| Languages counted | 12 | 12 |

Top languages in tensorflow/tensorflow: C++ (56.1% of code), Python (18.3% of code), C Header (10.5% of code). Top languages in pytorch/pytorch: Python (47.1% of code), C++ (25.8% of code), C Header (17.0% of code). C++, Python, C Header appear in both top language lists; Bazel, HTML appear only in tensorflow/tensorflow's top languages; CUDA, C appear only in pytorch/pytorch's top languages.

Methodology: both counts come from cached OctoCounts reports generated with tokei. tensorflow/tensorflow was counted at ref master (commit 016fafd6c00c) on 2026-09-21; pytorch/pytorch was counted at ref main (commit b6131af87744) on 2026-09-21. See the [counting methodology](https://octocounts.com/docs/methodology) for ignored directories and analysis options.
## About this comparison

tensorflow/tensorflow counts the TensorFlow monorepo: the C++ runtime and kernels, the Python frontend, XLA, and a large test and example corpus. pytorch/pytorch counts the PyTorch core repository: the Python frontend, the ATen/TH C++ and CUDA kernels, and its own tests and tooling. Both are full machine-learning framework source trees, counted on the dates shown in the methodology line above.

Both counted trees are framework source, not model code: whatever an application trains or infers with is written on top of these repositories, so neither number reflects what a user of the framework ships.

The per-language tables show a different center of gravity for each project — TensorFlow's counted code is dominated by C++ (kernels and runtime) while PyTorch's tree leans further toward its Python frontend — which is visible directly in the language breakdown rather than needing to be inferred from the totals.

_Repository size does not measure training speed, memory use, or model quality for a given workload — those depend on the kernels exercised and the hardware, not on how many source lines the framework tree contains._

Sources: [tensorflow/tensorflow repository](https://github.com/tensorflow/tensorflow) · [pytorch/pytorch repository](https://github.com/pytorch/pytorch). Statements verified 2026-09-16.

Evidence and next steps:

- [tensorflow/tensorflow SLOC report](https://octocounts.com/github/tensorflow/tensorflow)
- [pytorch/pytorch SLOC report](https://octocounts.com/github/pytorch/pytorch)
- [Compare tensorflow/tensorflow and pytorch/pytorch interactively](https://octocounts.com/compare?left=https%3A%2F%2Fgithub.com%2Ftensorflow%2Ftensorflow&right=https%3A%2F%2Fgithub.com%2Fpytorch%2Fpytorch)

Note: code size is not code quality. OctoCounts only reports reproducible line counts and makes no claim that either project is better.

## Compare FAQ

### Which has more lines of code, tensorflow/tensorflow or pytorch/pytorch?

tensorflow/tensorflow has more code: 5,100,331 code lines versus 2,563,680 for pytorch/pytorch, about 2.0x as much, based on cached OctoCounts reports as of 2026-09-21.

### Does more source lines of code mean more complexity?

Not necessarily. SLOC measures size, not complexity, quality, or maintainability. A larger codebase can mean more features, more generated or vendored code, more verbose language idioms, or more tests — none of which imply the code is harder to work with. Use SLOC to gauge the scale of what you'd be reading or maintaining, not as a quality signal for tensorflow/tensorflow, pytorch/pytorch, or any repository.

### How is this comparison calculated?

Methodology: both counts come from cached OctoCounts reports generated with tokei. tensorflow/tensorflow was counted at ref master (commit 016fafd6c00c) on 2026-09-21; pytorch/pytorch was counted at ref main (commit b6131af87744) on 2026-09-21. See the counting methodology for ignored directories and analysis options.

### Can I compare a different branch, tag, or commit?

Yes. This page shows the default branch for each repository. Use the interactive comparison tool to pick any public GitHub repository, branch, tag, or commit SHA for both sides and get a fresh side-by-side report.

## Related OctoCounts pages

- [Interactive repository comparison](https://octocounts.com/compare)
- [Recently analyzed repositories](https://octocounts.com/recent)
- [Popular SLOC reports](https://octocounts.com/popular)
- [Trending GitHub repositories](https://octocounts.com/trending)
- [Hall of Monoliths](https://octocounts.com/hall-of-monoliths)
- [Original research: how filtering changes SLOC counts](https://octocounts.com/research)
- [GitHub SLOC counter guide](https://octocounts.com/docs/github-sloc-counter)
- [Counting methodology](https://octocounts.com/docs/methodology)
- [SLOC and code metrics glossary](https://octocounts.com/docs/glossary)
- [OctoCounts API docs](https://octocounts.com/docs/api)
