Skip to content

FPSG-UIUC/nki-samples

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Neuron Kernel Interface (NKI) Samples

AWS Neuron is the software development kit (SDK) designed for ML chips AWS Trainium and Inferentia: purpose built for AI workloads. At the core of the Neuron SDK is the Neuron Compiler, which takes computation graphs from frameworks like PyTorch and JAX and converts them into highly optimized machine code.

NKI is a Python-based programming environment designed for the compiler which adopts commonly used NumPy and Triton-like syntax along with tile-level semantics. NKI also interoperates with the Neuron Profiler, providing insights into performance bottlenecks and instruction latencies. It offers tensor printing support, standard error messaging, and built-in kernel simulation capabilities for efficient debugging purposes. NKI offers two types of programming interfaces: NKI Language (nki.language) and NKI Instruction Set Architecture (nki.isa), enabling bare-metal access to the chip for full control.

alt "High-level flow of NKI in the Neuron Compiler. NKI emits IR immediately before the backend-IR compilation stage"

Documentation

The latest NKI documentation can be found on the AWS Documentation site, here. Documentation for NKI kernels are both inline (docstring) and available on the documentation site's kernel API reference page.

Repository Structure

src

reference

This folder contains the source code of the neuronxcc.nki.kernels, and they are optimized kernels from the Neuron Team serving as samples.

All kernels located in this folder have numeric accuracy tests and performance benchmarks defined in the test directory. We also demonstrate using these kernels end-to-end in our integration tests.

Note that these kernels are already being deployed as part of the Neuron stack. With flash attention as an example, compiling Llama models with transformers-neuronx will automatically invoke the flash_fwd kernel in attention.py. Therefore, replacing the framework operators with these NKI kernels likely won't result in extra performance benefit.

tutorials

The tutorial kernels are for educational purpose and include the kernels that are used in NKI guides. You can clone these sample kernels and run them directly while reading through the NKI documentation. These kernels are not necessarily high-performance, but contain detailed inline comments and have accompanying documentation.

test

unit

The unit tests directory contains unit tests and micro-benchmarks for standalone kernels. They run across multiple possible configurations, verify the numeric accuracy of the operation, and publish performance results to the micro-benchmark results.

integration

The integration tests folder contains integration tests of (selected) kernels. They verify the numeric accuracy of the model’s output, and publish end-to-end performance results into the integration benchmarks folder.

Maintenance Policy

NKI is currently released as beta while we gather feedback from our users and integrate it into the API. NKI API follow the Neuron SDK Maintenance Policy.

Getting Help

Have a look at the GitHub issues for this repository where you will find past issues customers have encountered with workarounds and clarifications. If you cannot find a suitable issue for your use-case feel free to file an issue to ask for assistance or to suggest improvements. Please read CONTRIBUTING.md for detailed information on submitting issues.

Contributing

We invite you to join the NKI community! If you'd like to share kernels you create with the community, we welcome your contributions to this repository via GitHub pull-requests as well as through filed issues discussing features, bug fixes, new use-cases, and API improvements. Please see CONTRIBUTING.md for more information

Licensing

This repository is licensed under the terms of the MIT-0 License

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 96.4%
  • Jupyter Notebook 2.8%
  • Shell 0.8%