PythonCK is a Python implementation of Composable Kernels tensor operations. The package is distributed as pythonck but provides three main modules that can be imported directly:
pytensor: Core tensor operations, coordinates, descriptors, and viewstensor_transforms: Tensor transformation parsing and analysistile_distribution: Tile distribution algorithms and visualization
pip install pythonck-0.1.0-py3-none-any.whlgit clone https://github.com/amir/pythonck
cd pythonck
pip install .import pytensor
import tensor_transforms
import tile_distribution# Create tensor descriptors
desc = pytensor.make_naive_tensor_descriptor([128, 256], [256, 1])
# Create tensor coordinates
adaptor = pytensor.make_tensor_adaptor([64, 128])
coord = pytensor.make_tensor_coordinate(adaptor, [0, 0])
# Work with tensor views
view = pytensor.make_tensor_view(desc, [64, 64], [0, 0])from tensor_transforms import TensorTransformParser
# Parse tensor transformation expressions
parser = TensorTransformParser()
result = parser.parse_expression("Transform<Merge<1, 2>>")from tile_distribution import get_default_variables, make_tile_distribution
# Get default configuration for specific examples
config = get_default_variables('rmsnorm')
# Create tile distributions
tile_dist = make_tile_distribution(
lengths_x=[256, 256],
lengths_y=[4, 2, 8, 4],
lengths_p=[2, 2]
)# Install in virtual environment
python -m venv myproject
source myproject/bin/activate # Windows: myproject\Scripts\activate
pip install pythonck-0.1.0-py3-none-any.whl
# Use in Python scripts
python my_tensor_script.py# In a Jupyter cell
import pytensor
from tensor_transforms import TensorTransformParser
# Your tensor operations here...# Install in Pyodide
import micropip
await micropip.install("pythonck-0.1.0-py3-none-any.whl")
# Import and use
import pytensor
from tensor_transforms import TensorTransformParserSee PYODIDE_USAGE.md for detailed Pyodide/Quarto instructions.
The repository also includes Streamlit applications for interactive exploration:
# These are NOT part of the wheel - run from source
streamlit run app.py # Main dashboard
streamlit run tensor_transform_app.py # Transform analysis
streamlit run tensor_visualization_app.py # Tensor visualization
streamlit run thread_visualization_app.py # Thread mappingpythonck/ # Repository root
├── pytensor/ # Core tensor library
├── tensor_transforms/ # Transform parsing
├── tile_distribution/ # Tile distribution
├── app.py # Streamlit apps (not in wheel)
├── tensor_transform_app.py
├── tensor_visualization_app.py
├── thread_visualization_app.py
├── tests/ # Test suite
└── dist/ # Built wheels
└── pythonck-0.1.0-py3-none-any.whl
✅ Library Code:
pytensor/- All tensor operations and utilitiestensor_transforms/- Transform parsing and analysistile_distribution/- Tile distribution algorithms
✅ Documentation:
- README files and implementation status
- Module docstrings and type hints
❌ NOT Included:
- Streamlit applications (these are demos, not library code)
- Test files
- Development tools
- Required:
sympy>=1.9(symbolic mathematics) - Optional:
matplotlib,numpy,pandas(for visualization features) - Development:
pytest,black,isort,flake8
import pytensor
# Create a tensor adaptor and coordinate
adaptor = pytensor.make_tensor_adaptor([64, 128])
coord = pytensor.make_tensor_coordinate(adaptor, [5, 10])
print(f"Coordinate offset: {coord.get_offset()}")from tensor_transforms import TensorTransformParser
parser = TensorTransformParser()
transform = parser.parse_expression("Transform<PassThrough<0, 1>>")
print(f"Parsed: {transform}")from tile_distribution import make_tile_distribution
# Create a 2D tile distribution
dist = make_tile_distribution(
lengths_x=[256, 256], # Tensor dimensions
lengths_y=[4, 2, 8, 4], # Thread hierarchy
lengths_p=[2, 2] # Partition dimensions
)
print(f"Distribution created with {dist.get_num_of_dimension_x()}D tensor")To build the wheel yourself:
# Install build tools
pip install build
# Build the wheel
python -m build --wheel
# Install the wheel
pip install dist/pythonck-0.1.0-py3-none-any.whl- Repository: https://github.com/amir/pythonck
- Issues: https://github.com/amir/pythonck/issues
- Documentation: See module docstrings and README files