-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Polish and officially release quantized types #4857
Comments
Before writing a formal RFC, I would like to briefly summarize some previous discussions on this topic. I think there are still some issues to be solved, and I hope to continue the discussion here. BackgroundA quantized type normally has no native support. Therefore, you need to specify a parent primitive type (e.g. a 32-bit int) and describe how you would like to pack a group of quantized types (e.g. a 15-bit int and a 17-bit int) inside. In Taichi, this is done by introducing two SNode types, i4 = ti.quant.int(bits=4)
u28 = ti.quant.int(bits=28, signed=False)
p = ti.field(dtype=i4)
q = ti.field(dtype=u28)
ti.root.dense(ti.i, 4).bit_struct(num_bits=32).place(p, q)
r = ti.field(dtype=i4)
ti.root.dense(ti.i, 4).bit_array(ti.i, 8, num_bits=32).place(r) What are the problems of current APIs?
What are our current thoughts on solving the problems?As Potential change 1: add type
|
I really like 1, because it makes the type system neat :-) However, considering that changing to |
+1 on implementing #2 as a start! Btw I feel like based on the deployment need, not modifying computation code might not be as hard requirement as we thought. IMHO if it's a |
I agree with that. The main point here is, when we introduce a new language construct, especially as fundamental as a type, we should let it make sense in most cases, instead of being a deployment-only thing.
IMO yes. @k-ye |
After an offline discussion with @ailzhang, we reach the following consensus:
f_ty = ti.types.fixed32(scale=100.0, signed=False)
arr = ti.ndarray(float, 10)
@ti.kernel
def foo(a: ti.types.ndarray()):
for i in a:
x = ti.cast(a[i], f_ty)
... # calculations on x
a[i] = ti.cast(x, float)
foo(arr) WDYT @k-ye |
To me it seems like
it's also not too hard to convert custom quant types into primitive types. One thing I've been thinking about: if we make quant vectors workable on mobile, how much larger scale can we get for simulation. Note that graphical APIs are already offering So yeah, I guess we can agree that Ndarray doesn't need to support fancy |
@k-ye Yup that wrapper is mainly used to solve the floating point atomics problem we've seen. Is it correct understanding that to achieve much larger scale simulation on mobile, we can try adding e.g. |
Yep. Additionally, this could also help with vec4 loading optimization (cc @turbo0628 @qiao-bo ) |
This indeed requires us to support quantized scalars. Our current APIs cannot be used outside SNodes. However, when a quant type is used as an individual scalar, number of bits other than 32/64 doesn't make sense. As there are already
I don't quite get the point here. Using native |
After yet another discussion with @k-ye @ailzhang @jim19930609, I have formed a mental picture of future plans and would like to share it here. Task A: Refine current APIs of quantized types and make them available againAlthough current APIs work only in the SNode system, they are still useful and we hope to expose them in a cleaner way. Subtask A.1: Determine public APIs of quantized type definitionsPreviously, we have two groups of APIs, We would like to only keep To sum up, we will have Subtask A.2: Solve the inconsistency problem of
|
minor nit: for subtask b.2, I wonder if |
Thanks for writing this up! Overall it looks like a great roadmap. I have a few questions here: Could you provide an overview of the quant API? Subtask A.1
I wonder if Subtask A.2
nit: I feel like we don't have to have both |
For struct it can make sense as well..
|
I think there are different ways to handle this: use |
Ah yes. I was stuck at the assumption that we could not break the two same-level classes, Now I have a new design: we get rid of the legacy "type_factory" and directly provide the following APIs - BTW which one seems better, |
Cool! I prefer |
+1 on |
I feel like in real use cases shared exponents are typically used only in vectors. Do you have an example where you need that in a struct? :-) @strongoier Another question of mine: if I'd split the 64 bits into |
Not really. My point here is just that we don't have to throw an error if those fields are not grouped as a vector.
In fact we hope that elements of a vector have the same type. A quantized struct is needed for this purpose. |
I see. Thanks for the clarification! I feel like the user may want to access the components via |
Yep. It is fine to support that as syntax sugar. |
I'm thinking about this: for |
I understand your point here. TBH this touches some underlying design philosophy of Taichi, which I get a bit confused from time to time. As far as I understand, in earlier Taichi a As time goes by, different voices arise in the community. Many users consider vectors as containers of contiguous same-typed values. As a result, many recent or planned efforts go in this direction - dynamic indexing, native types, etc. However, these two directions are inherently conflicting - giving more support to one of them means giving less support to the other. To avoid getting design choices back and forth, IMHO we need to have a consistent and clear underlying principle. Then we can easily determine whether a quantized vector can have components with different types. BTW I have another question: why do we have a |
I also agree on this. We have spent some great amount of time debating on this, and concluded that vector/matrix should behave just like how most users would expect: They are containers holding homogeneous elements, dynamically-indexable, and providing linalg methods. Most of the time, using a Taichi vector/matrix should feel no different from using a GLM/GLSL one. It simplifies the user experience, the API design and the implementation. If it comes to a point where a non-trivial amount of usage for heterogeneous-vector show up, 1) From a storage point of view, this could supposedly be implemented via quant structs; and 2) we should consider how to offer a proxy/adaptor to help them convert between this quant struct and vectors (in the mathematical sense). WDYT? |
After yet another discussion with @Hanke98 @k-ye @ailzhang, I would like to share some updates. In Taichi v1.1, we hope to first release a refined version of quantized types used with SNodes, in order to get this feature officially announced and tried by users. The TODO list of this whole issue is thus shuffled by priority, and I'll track v1.1 blockers here:
Quantized types definition refinement planWe only present three basic quantized types,
|
Just one comment, I wonder if we can put |
Unfortunately, we only have a |
Let me share some updates here. All planned refinement in #4857 (comment) has been realized and announced to users in Taichi v1.1. Furthermore, current codegen regarding quantized types is independent of SNode now, which allows flexible extensions in the future. A potential future direction is to allow quantized types in Ndarrays (similar to #4857 (comment) task B), which will get implemented when more real requirements arise. |
…tion (#6074) Related issue = #5959, #4857 Support for different element types of matrix fields was introduced in #2135 for quant. As discussed in #4857 (comment), the only case we need to support is different element types with **same compute type**. This PR adds the validity check and removes test cases which are actually not allowed. <!-- Thank you for your contribution! If it is your first time contributing to Taichi, please read our Contributor Guidelines: https://docs.taichi-lang.org/docs/contributor_guide - Please always prepend your PR title with tags such as [CUDA], [Lang], [Doc], [Example]. For a complete list of valid PR tags, please check out https://github.com/taichi-dev/taichi/blob/master/misc/prtags.json. - Use upper-case tags (e.g., [Metal]) for PRs that change public APIs. Otherwise, please use lower-case tags (e.g., [metal]). - More details: https://docs.taichi-lang.org/docs/contributor_guide#pr-title-format-and-tags - Please fill in the issue number that this PR relates to. - If your PR fixes the issue **completely**, use the `close` or `fixes` prefix so that GitHub automatically closes the issue when the PR is merged. For example, Related issue = close #2345 - If the PR does not belong to any existing issue, free to leave it blank. --> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Quantized types are an experimental feature introduced in the QuanTaichi paper. With this useful feature, users can significantly save memory usage of their Taichi programs. The feature can also enable acceleration of atomic operations on mobile phones.
However, the feature has been neither officially announced nor extensively maintained. As Taichi has come to its 1.0 version, I think it is time to polish the feature and make it available to users. My plan is to refine the API and implementation so that it can fit into current Taichi better, be more user-friendly, and become deployable with Taichi AOT. I would like to write an RFC for it.
The text was updated successfully, but these errors were encountered: