Lazy-load TensorFlow for TFRecord-specific pipeline paths
Maintainers usually reply within 2 days
@hanzalaareeb is already working on this.
Since Aug 20, 2026.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
- Issue type
- Refactor
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- python, tensorflow
- Domain
- data-engineering, machine-learning
Research direction
Start with dpsynth.data_generation and dpsynth.pipeline_transformations.input_output, then inspect the tfrecord_descriptor import path and its TFRecord-specific I/O branches. Run the provided Python import check to confirm non-TFRecord modules leave TensorFlow out of sys.modules, then run the pipeline tests and verify the existing 11 tests pass.
Written by the indexing model from the issue text.
Description
Summary
This PR removes eager TensorFlow initialization from shared pipeline import paths.
Previously, importing non-TFRecord pipeline functionality could transitively import TensorFlow:
dpsynth.data_generation
→ creating_data_recorder_converter
→ tfrecord_descriptor
→ tensorflow
As a result, workflows that do not use TFRecord, including the SWIFT pipeline test, still required TensorFlow to initialize successfully during module import.
This PR defers TFRecord-specific imports until DataFormat.TFRECORD is selected and imports TensorFlow only inside TFRecord-specific I/O paths.
Changes
- Lazily import
tfrecord_descriptorwhenDataFormat.TFRECORDis selected. - Move TensorFlow imports into TFRecord-specific branches in pipeline I/O.
- Preserve TensorFlow type annotations using the existing
from __future__ import annotationssupport andTYPE_CHECKINGimports without requiring TensorFlow at module import time. - Add regression coverage to verify that importing non-TFRecord pipeline modules does not load TensorFlow.
- Preserve existing public APIs and dependency extras.
Why
Python executes module-level imports when importing a module. The previous import structure therefore initialized TensorFlow during test collection:
pytest collection
→ import SWIFT test
→ import shared DPSynth modules
→ import TFRecord implementation
→ import TensorFlow
This happened before any SWIFT test executed.
The SWIFT workflow uses PipelineDP's LocalBackend and a dummy record converter and does not require TFRecord support. However, it could still be blocked if TensorFlow failed to initialize in the environment.
The change makes TensorFlow initialization conditional on actually entering a TFRecord code path:
shared pipeline import
→ select data format
├── non-TFRecord → TensorFlow not imported
└── TFRECORD → load TFRecord implementation → import TensorFlow
This preserves TFRecord support while preventing unrelated pipeline workflows from depending on successful TensorFlow initialization.
Verification
Confirmed that importing the shared modules no longer loads TensorFlow:
python -c "import sys; \
from dpsynth import data_generation; \
from dpsynth.pipeline_transformations import input_output; \
assert 'tensorflow' not in sys.modules"
The previously blocked pipeline tests now complete successfully:
11 passed
Some unrelated JAX, Beam, httplib2, and Pyparsing warnings remain.
- Dominant language
- Python
- Stars
- 32
- Forks
- 13
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 20
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from google/dpsynth
-
import dpsynth fails because mbi.Dataset is registered as a JAX dataclass twicePossibly taken @hanzalaareeb claimed this 10 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 2 days
-
Clarify installation requirements in quickstart.ipynbPossibly taken @hanzalaareeb claimed this 9 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
google/dpsynth#194 · 1 comment ·
Maintainers usually reply within 2 days
-
`IndependentConfig` synthesis raises "Cliques must be unique."May be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 2 days
-
Windows install of pylock.toml fails on the pipeline extra due to missing Windows wheel for python-dpPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 3/5 1-2 days Newbie friendliness 72/100
Maintainers usually reply within 2 days
-
Add an option to control the maximum marginal degree in AIM workload constructionPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 3/5 1-2 days Newbie friendliness 65/100
google/dpsynth#199 · 3 comments ·
Maintainers usually reply within 2 days
Similar issues
-
area/install reliability
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
FluidNumerics/fluid-walk-blocker#191 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
TransformerLensOrg/TransformerLens#1868 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
climate-analytics-lab/jax-gcm#1057 ·
Maintainers usually reply within 1 day