This PR brings up the tirx namespace. We have been spliting out the
original tir namespace to include high-level component s_tir and this PR
updates the remaining low-level part as tirx namespace
This PR enables ruff pyupgrade (UP) rules with py310 target, auto-fixing
~5600 annotation modernizations (PEP 585 generics, PEP 604 unions,
deprecated typing imports).
Also removes from __future__ import annotations from ir/module.py and
rmsnorm.py, bumps requires-python to >=3.10, and removes absolute_import
aliases from topi/contrib files.
This refactor introduces a base Executable class and a `tvm.compile`
interface that can be used to compile both TIR and Relax programs.
`tvm.compile` will return an Executable object that can be used to call
either TIR or Relax functions.
* [REFACTOR] Phase out te.schedule python components
This PR phases out te.schedule python components.
te.compute is kept around for future usages.
tir.Schedule is a more modern version of the scheduling that we can use onwards.
Doing so also helps us to cleanup the testcases that relies on
explicit full build and execution. As we move future unit testcases
towards structural equality based unit tests.
* Simplify CI to focus on UT
The main rationale is that we should only have very few target
dependent UT in tests/python/codegen and possible
a new category in future for op-level integration if needed.
* Re-enable wasm
* fix lint
* remove hybrid,sparse autodoc and remove tests
---------
Co-authored-by: Siyuan Feng <hzfengsy@sjtu.edu.cn>
This PR starts the step 0 to phase out relay from the current
development main branch. This PR focuses on the python
components of relay, autotvm, auto_scheduler. To make the change
manageable, we will also do followup steps on te.Schedule and
c++ components in followup PRs.
To continue support community members who depends on
legacy flows, the [v0.19.0](https://github.com/apache/tvm/tree/v0.19.0)
branch will continue contain these components.
As noted in [discussion on phasing out legacy components](https://discuss.tvm.apache.org/t/phasing-out-legacy-components/17703/30),
this would help us to do two purposes:
- By removing outdated or redundant elements, we can significantly
reduce complexity and improve maintainability.
- Unify our focus: Concentrating our efforts on the new unity flow
will allow for more efficient development and innovation.
It is also a good opportunity for us to revisit and reduce CI time.
The past relay legacy flow contains a lot of end to end tests that
requires hardware resources to run and causing long CI time.
Moving onwards, we can focus more on unit-tests that focuses
on structural equality and runs within seconds, while be mindful
about tests that requires hardware resources (by restricting them
to specific folders and CI nightly in some cases).
---
Co-authored-by: Siyuan Feng <hzfengsy@sjtu.edu.cn>
* [Docs] Introduce Relax API and move legacy part to standalone page
As the TVM project evolves, the Unity strategy has been the recommended
way to use Apache TVM applications. Hence, we are pushing documentation
for the Relax API to the forefront and moving the legacy part to a
standalone page, which may be removed in the future.
* update for ci
* update for ci
* [IR] Default to empty attributes, instead of NULL
Prior to this commit, the default `DictAttrs` for an `IRModule`,
`tir::PrimFunc`, `relax::Function`, and `relay::Function` was a null
value. At each callsite, the absence of a `DictAttrs` needed to be
treated as equivalent to an empty `DictAttrs`. In C++, this typically
was done using the `foo->GetAttr` helper function, but in Python it
needed to be checked explicitly. That is, every callsite needed to
check `if func.attrs is not None and attr_name in func.attrs`, rather
than only checking `if attr_name in func.attrs`.
Since most functions would have at least one attribute to specify the
global symbol, these bugs would often surface when working on
unrelated changes.
This commit changes the default attribute dictionary from
`NullValue<DictAttrs>()` to `DictAttrs()`. This avoids having two
separate representations of an object without any attributes, and
allows the `if attr_name in func.attrs` pattern in the Python API.
* Remove no-longer-needed checks on attrs being present
* Fix up unit tests
* More unit test fixes
* Undo erroneous find/replace
* A few more unit tests
* Provide `DictAttrs.get`
Prior to this commit, if a lowered `IRModule` does not contain any TIR
functions, `tvm.relax.build` provided an empty `tir_mod`, which caused
a segfault during TIR compilation. This could occur when
`tvm.relax.build` is called without an explicit target argument, for a
module that does not define any virtual devices.
This commit updates the `_filter_tir` utility function to return
`None` if there are no TIR functions, rather than an empty
`IRModule`. In addition, checks for an empty `IRModule` are added to
`tvm.build` and `TIRToRuntime`, so that a similar failure mode would
raise an exception rather than producing a segfault.
* [Unity] filter out non-GPU primfuncs in default_gpu_schedule
* Add relex heterogeneous e2e case
* Remove get_prim_func_device
* Update test cases
* Fix flake8
* fix lint
* Add test case for change of default_gpu_schedule
* fix comment
Hopefully fixes#12742, as the warning should only be printed when a user passes `target_host`, in the current case if the user passes `None` as `target_host` it'll be processed by `canon_target_map_and_host` which seems to always produce a `target_host` and thus triggering the warning despite the user doing nothing wrong.
Previously, if a TIR Schedule is passed to `tvm.lower`, the error
message is returned `ValueError: ('Expected input to be an IRModule,
PrimFunc or Schedule, but got, ', <class
'tvm.tir.schedule.schedule.Schedule'>)`. This can cause user
confusion, as the expected class name in the error message does not
differentiate between between a `tvm.te.Schedule` and a
`tvm.tir.Schedule`. Updated error message to explicitly state that
this should be a `te.Schedule`.
* Finish support for list-of-targets
This finishes the work started in https://github.com/apache/tvm/pull/11173 to support
'external codegen' targets in the N build-like API surfaces.
- It turns out it's ok if a build is given only a single 'external codegen' target, so remove that check
in CompilationConfig::Init. When Collage builds a 'candidate partition' it does so for a single target.
As far as Collage is concerned it does not care whether the target is regular (eg Target("cuda")), or
for a specific external codegen (eg Target("cutlass")), it just passes the target into the build.
- Add CompilationConfig::FindPrimitiveTargetForKind which I'll later need to retrieve
the external codegen Target instance corresponding to a "Compiler" attribute value.
- Target.update_target_host_consist was supporting three API styles:
- single target
- map from device type to target
- map from target to IRModule (for the ir_to_runtime API)
I replaced all those calls with a more specialized 'canonicalize' call:
- Target.canonicalize_target_and_host
- Target.canonicalize_multi_targets_and_host
- Target.canonicalize_target_map_and_host
In particular, all the tuning interfaces (task extraction, tuning, tuning records) all explicitly
*do not* support multiple targets since the underlying code just doesn't support that.
* - Lints
- Revert unintended changes
* - more lints
* - Fix model_library_format handling of target.
- Improve comments in compilation_config.h
* - Lints
- Update target/target_host params documentation
* - Fix micro library format tests
- Rev micro library format from 5 to 6
- Use Target.current() in a few places
* - eta contract comprehension
* - Woops, one more device: target map left
- Handle host already being in Target
* - lint
* - lint
* - Bug with append
- Take device type from target
* - Fix hexagon
* [Driver] Remove duplicate PreProcessModuleForBuild
`PreProcessModuleForBuild` was nearly identical to the `build()`
function in the same file.
* Name change, `tvm::TIRToRuntime`.
* change default name of tvm.build() to None
* change lower name default to None
* fix lint
* lower() use "main" -> "default_function"
* remove default name's warning
* [TVMC][Relay] Introduce executor and runtime parameters
This introduces `executor` and `runtime` into the various entrypoints but also into `tvmc` as `--executor` and `--runtime`. This touchs a lot of files and I've tried to update anywhere as necessary.
Notable, executor code generators now accept the initial `IRModule` rather than creating
it themselves so it can be annotated once.
Validated the demo application continues to classify the tabby cat with
new CLI options.
* Correct Graph Executor Python API
* [TE] Light refactoring of TE -> TIR paths.
- Added ScheduleToPrimFunc, extracting out common behavior in
ScheduleToModule and auto_scheduler's feature extraction.
- Added `tvm.driver.build_module.schedule_to_module`, to avoid needing
to 4-line boilerplate needed to do so. Also makes deviations from
the usual path (e.g. `debug_keep_trivial_loop`) much more explicit.
* Removed schedule_to_primfunc, replaced usage with schedule_to_module.
* Returned C++ function ScheduleToPrimfunc to be inside ScheduleToModule.
* Initial investigation
* More progress!
* More progress / notes
* rewrite build_for_device mostly in c++
* More progress
* Initial split of transformations applied to device and host as post split action from mixed module
* Combine duplicate passes after spliting mod on aot and vm flows
* Minor cleanup
* Move target mangling to driver_api.cc
* Move more build utlities to cpp driver api
* [Build][WIP] Moving build utilities to C++ from Python
* [Build] Remove comments
* [lint] Pass black
* More formating
* Move more build functionality into cpp
* Remove comments
* Remove unused defs and imports
* Address PR comments
* More PR comments
* More comments
* More comments
* Add comments on the new split function
* Fix PR comments on clarity
* Test CI
* Fix format
* Refactor build
* Expose splitted composite passes to python
* Format files
* Test fix
* Fix for annotating entry funcs on code targeting CPU
* Prevent entry funcs to be annotated when compiling for CPU with C runtime enabled
* Guard for aot executor entry
* Sphix format
* Sanity fix
* Sphinx fix
Co-authored-by: electriclilies <lilyorthsmith@gmail.com>
* rename _update_target and document its function
* make tvm.build return OperatorModule to return multiple outputs
* allow retrieving the var names used in TIR repr
* add Operator Model Library Format and test
* Add pathlib convenience functions to utils.TempDirectory.
* fix tests
* black format
* git-clang-format
* pylint fixes
* add asf header
* change memory map to make more sense, fix tests
* address giuseros comments
* align GetVarName with future TypedPackedFunc
* fix test
* clang-format
* rev model library format to v4 (bad merge)
* [Docs] Prevented docs/1 file from being generated.
Typo in tests/scripts/task_sphinx_precheck.sh caused $TVM_HOME/docs/1
file to be created with stderr output, rather than merged stderr and
stdout.
* [Docs] Corrected sphinx build warnings
- Previously, several warnings were generated by sphinx, but were
unintentionally suppressed. This PR resolves the sphinx warnings.
* [Docs] Corrected additional sphinx build warnings.
- Rebased on main and corrected warnings, now up to date as of commit
53e4c603.
* [Docs] Corrected additional sphinx build warnings
- Rebased on main and corrected warnings, now up to date as of commit
1f2ca068c.
* [Docs] Corrected additional sphinx build warnings
- Rebased on main and corrected warnings, now up to date as of commit
d0791d3db.
* [Docs] Ignore sphinx warnings from missing "git describe" and sckit-learn versions.
Co-authored-by: Eric Lunderberg <elunderberg@octoml.ai>
* Fix legacy code on target host
* Modify legacy code for target host change
* Add tests and fix merge issue
* Add condition for same host
* Modify all files for new target host api compatibility
* Add newline
* Change import format
* Optimize test file
* Add match error info for unit tests
* Fix for heterogeneous targets
* Fix format for dict iteration
* Fix target host type error
* Skip one testcase for tvm infinite loop bug
* Fixed bug for target map compatibility
* Fix another TargetsMap issue
* Fix typo and infinite loop error
* Temporary fix for handle issue
* Fix vm target
* Add condition support for str case
* Add GetHost function and fix previous bugs
* Fix measure_record.cc
* Fix search_task.cc
* Fix compiler.cc, memory_alloc.cc
* Fix driver_api.cc
* Fix format
* Fix bugs and GetHost function usage
* Fix clang format
* Fix bug
* Modify python tests
* Change python unit tests to new target api
* Fi test_runtime_heterogeneous.py
* Modify tutorials & remove extra print
* Update more tests to new api
* Refine the tutorial target usage
* change argument name for Target constructor function
* Fix target export function
* Fix and validate all tutorial usage
* Remove unused argument
* Fix format
* Fix bug in driver/build_module.py for heterogeneous target
* Fix bug in driver/build_module.py for heterogeneous target more
* Fix target host type error
* Fix cudnn target host bug
* Fix according to reviews, add helper function in python
* Refactor code as helper function
* Expand helper function
* Fix bug add and update python helper function
* Update target hosts
* Fix format & refresh function
* Fix unit test bug
* Fix bug in refreshing host
* Fix bug
* Add SetHost function
* Update export function
* Fix format
* Fix export bug in target
* Fix bug on host referencing
* Addtional tests
* Address review issues
* Fix format target.py
* Fix issues and format
* Add some 3rd party dependencies
* Merge main branch
* Fix target.h format
* Remove redundent import
* Fix function name
* Add parameter name
* Fix new code bug
* Fix bug in lowering
* Created CSourceMetaData module for model metadata
* Currently, there is a MetaData module to capture constants
conditionaly if the runtime modules implement const init
PackedFuncs. However, this one relies on a load process
in which the metadata is created on volatile memory that
may be not usable in uTVM environments.
* There is a need for model level metadata that is valid
across all runtime modules such as the func registry
when creating a system-lib.
* This commit implements a CSoureMetaData module to hold
func registry that collects function names from the
runtime module and generates a c source file to be
linked with final artifact.
* Modified and added export_library for utvm
Change-Id: Ie2e8e2aea1a66520f03fe8af7cc5bdf27339ea10
* Created CSourceMetaData module for model metadata
* fixed llvm_module to return null pfs for
get_symbol and get_const_vars
Change-Id: I84810e0695d4d6fb314af2469117f965eed71b51
* Created CSourceMetaData module for model metadata
*fixed bundle_deploy tests
Change-Id: I0d1332a4abbb6830531784c59264021bbbd7148a
* Created CSourceMetaData module for model metadata
*fixed export_library not to insert "options" when targeting tar
*fixed unit tests
Change-Id: Ia1686889498b71af66f1a0311a059154ad3c2c3e
* Created CSourceMetaData module for model metadata
* enable wasm to support csource metadata module
* disabled non DSOExportables from using csource metadata module
Change-Id: Ie09beaad35cbc2ef738d1d24d91e249b5e099569
* Created CSourceMetaData module for model metadata
* changed const pfs to be called only on external modules
or DSOExportable modules
Change-Id: I6ad28f166c0fc27a2548c851bf9287ec805550d1
* Created CSourceMetaData module for model metadata
* CSourceMetadata module wrapper is only created for c/llvm targets
Change-Id: I13cb4140c17e2e1f91d495b15a1ff7eeab9fb14d
* Created CSourceMetaData module for model metadata
*target should be defined to use csourcemetdata module
Change-Id: Id8e55b23d0007a79c550334de2c0fec63d40171f
* Created CSourceMetaData module for model metadata
* reinstate llvm func registry
Change-Id: I53e0754b6fb533637f08b25e98064d8c04092de4
* Created CSourceMetaData module for model metadata
* addressed comments and fixed bugs
Change-Id: I26401685dc803aeaf7642c865df88d683419e859
* Created CSourceMetaData module for model metadata
* addressed a missed comment
Change-Id: I65e65c30bc780a946f3f1b8372c40a49a5c20582
* Created CSourceMetaData module for model metadata
* te build interface should only include c-source metadata if
targetting "c"
Change-Id: Ie23cb8c6231c1f2de6d2827084774e3510288098
* Created CSourceMetaData module for model metadata
* c_source modules should be created only if they are
non-DSO exportable
Change-Id: I53f2f8e9caa41f133446f8881b9dc541ebeee8cc
* Created CSourceMetaData module for model metadata
* documetation misalignment in source_module.cc
Change-Id: I83e2c29b1f2980ca65a694304720dc58a5cb7879
* Created CSourceMetaData module for model metadata
* typo : same object file written as a dependency in the Makefile
Change-Id: I8becc4196d286cfb6372768687b3c836799dcb78
* Created CSourceMetaData module for model metadata
* removed unused param from a brief
Change-Id: Ie4db2aca3b7ea147bd8c65ef5d1cc2146f530e76
* Created CSourceMetaData module for model metadata
* made export library use c as the format for c source modules
Change-Id: Ie2fd6204414f0fa43988a8082d18af7a3225e237
* Created CSourceMetaData module for model metadata
*addressed a nit
Change-Id: I6084b8c06ddfaaece295439dbab589e6e202b664
* Add ChangeDatatype pass and unittest
* [WIP] Jared's work on Fri
This was work that Jared did on my computer, trying to get Inception v3 running.
* Fix simplify inference to work over different data types.
* Formatting
* Copy setup code from other test file
* Logging in Relay
* Remove duplicate TVM_DLL
* Add Sub, Mul, Div, Max to bfloat lib
* Fix previous broken rebased commit
* Remove line
* Add LowerCustomDatatypes to build passes
* Upcast ints to custom datatypes too, as well as to floats
* Add and use convert_ndarray
* Lower Call
* Relay: create constant scalars of custom dtypes
We use the same method we use in TVM: store the value in a double.
* Custom datatype formatting in Relay
* Update unittests
* Add simpler example that's not working yet
* Add Python unittests to Makefile
* Fix bug
* Fix function name in GetPackedFunc call
* convert_ndarray makes its own executor
* Add simple test case
* Move setup() calls
* Use convert_ndarray
* Change import to make it more specific
* Fix another Registry::Get call
* Allow users to register minimum functions for custom datatypes
This commit allows users to register global functions named
`tvm.datatype.min.<type name>` which take the number of bits in the custom type
and return the corresponding minimum value (as a double).
A similar commit will need to be created for max, whenever that ends up being
needed!
* Remove check for float
* Add test
* Fix inception test
* Add MobileNet
* Lower custom datatypes before intrinsics
* Add exp and sqrt bfloat functions
* [buggy commit] Lower intrinsics like sqrt, exp
This commit has bugs in it, I'm fairly certain.
* Formatting
* Fix bug
* Add lowering for new ops in test
* Add int to bfloat
* Remove print
* Add all tests
* Correct image size
* Add TODO
* Add "notbfloat" type
This type is for testing purposes. It just stores a float in a uint32. It was
used to confirm the fact that my bfloat "implementation" is very numerically
unstable and was causing issues when running the model.
* Convert arguments
Not sure how necessary this actually is.
* Rewrite custom datatype constants in Relay
* Add test_ops
* Print constants in Relay
* Use topi.testing
* Test conv2d
* Add test_model
* Comment out model tests
* Register notbfloat
This could be unregistered at some point later
* Add commented code
Remove later
* Add posit tests
* test_ops_same_function
* [temporary] move incomplete commit to macbook
* Add more to tests
* Formatting
* Uncomment add
* Remove bad tests
* Change comments
* Change function name and docstring
* Change main function
* Restructure tests
* Fix visibility of posit functions
* YAPF
* Switching keywords around to resolve build errors on some systems
* Improve test by running smaller mobilenet
* Add test_cast
* Change datatype name; add simple test
* Rename to posit32
* Merge 3 posit types into one file
* Add a nop type
* Remove bfloat
* Refactor test comments
* Refactor conv2d test
* Add optional tolerance arguments
* Add posit8 and posit16
* Add comment about posit8
* Whoops -- actually add noptype to CMakeLists
* Add rtol, atol to run_workload
* Add noptype to tests
* Run noptype over other models, too
* Pass correct arguments to calls
* Fix line length errors
* Raise tolerances (again) to avoid flaky test
* fix style
* add test for tanh, log, sigmoid
* Remove references to bfloat, notbfloat
* Change comments
* Remove old test file
* fix min func
* refactoring unit test file
* use posits es2
* cleanup
* comment
* coment if_then_else
* support different bit widths
* use random seed to create stable tests
* update documentation
* removed nop-type and code consistency
* add batchnorm test
* rebase and update
* fix tests and format
* pylint
* change order of include
* include order
* fix style
* remove posit c linkage
* update universal
* fix style
* fix test
* fix overflow error with minfunc and posits
* style
* use change_dtype to convert params
* update universal
* fix fatal error
* fix constant repr
* minor update to posites2
* update universal
* fix rst
* fix invalid import and sqrt
* update universal
* comments
* comments and expand testing
* increase atol/rtol for custom[posites2]32
* Re-add newline
* Remove comment
* Remove opt level and comment
* Change docstring
* Add TODO
* Add file header and newline
* Update docstring
* Update file docstring
* Update docstrings
* Delete todos
* create_min_lower_func
* add better debugging message
* docs
* add BYODT tutorial
* add todo
* Reformat some of tutorial to RST, plus code fixes
* tutorial notebook runs now
* fix hyperlink
* rebase
* add to tutorial
* fix mobilenet model
* add skip tag
* black lint
* add compiler flag and add dummy float
* myfloat and posites2 test
* remove universal
* lint
* lint
* add setup
* build with USE_POSIT for CI/CD
* fix posit cmake
* add cd /
* undo docker changes
* change tutorial to use myfloat
* move files
* lint
* fix
* remove filter
* fix lint
* fix suggestions
Co-authored-by: Jared Roesch <roeschinc@gmail.com>
Co-authored-by: Andrew Liu <andrewlliu@gmail.com>
* Add `set_attr_preprocessor` to TargetKind registry, which is used to pre-process attribute maps.
* Use `set_attr_preprocessor` for NVPTX and ROCm backend to check and add mcpu and mtriple.
* Add TargetTag registration and retrieval on C++ side and python side. Allow creation of Target using the tag name.
* Unify target creation on C++ side, replace Target::Create and Target::FromConfig with the constructor.
* Unify target creation on python side, deprecate tvm.target.create and encourage direct use of the constructor of tvm.target.Target instead.
* Add initial support for composite target.
* Block scope hoisting added
* lowering flow added with 2 variants
* Fake commit to trigger ci with pass default enabled
* CI Failure resolved
* Optimize for if var list iteration
* More test case added
* Fake commit to disable failed test cases
* Pass default value restored
* [1] Review comment handled
* [2] Review comments handled
* [REFACTOR][TIR] Migrate BuildConfig to PassContext.
This PR migrates the TIR configurations from BuildConfig to the
PassContext used by the unified IR.
Moving forward, PassContext will be the unified way to configure passes in the TVM stack.
Changes
- Refactored TVM_PASS_REGISTER_CONFIG_OPTION to take in the reference type.
- Removed BuildConfig.
- Migrated the passes to use PassContext.
* Update include/tvm/ir/attrs.h
Co-authored-by: Zhi <5145158+zhiics@users.noreply.github.com>
Co-authored-by: Zhi <5145158+zhiics@users.noreply.github.com>
Buffer configurations can be passed during construction
and does not need to be part of the build config.
This is a refactor step to simplify the BuildConfig for the PassContext migration.