-
Notifications
You must be signed in to change notification settings - Fork 2
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
DType refactoring #1
Open
siberie
wants to merge
5
commits into
jkrukowski:main
Choose a base branch
from
siberie:feature/dtype-refactoring
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import Foundation | ||
import CoreML | ||
|
||
|
||
public enum DType: String, Codable { | ||
case float64 = "F64" | ||
case float32 = "F32" | ||
case float16 = "F16" | ||
case int32 = "I32" | ||
case uint32 = "U32" | ||
case int16 = "I16" | ||
case uint16 = "U16" | ||
case int8 = "I8" | ||
case uint8 = "U8" | ||
case bool = "BOOL" | ||
} | ||
|
||
extension DType { | ||
var scalarSize: Int { | ||
switch self { | ||
case .float64: | ||
return MemoryLayout<Double>.size | ||
case .float32: | ||
return MemoryLayout<Float>.size | ||
case .float16: | ||
return MemoryLayout<UInt16>.size | ||
Comment on lines
+25
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why |
||
case .int32: | ||
return MemoryLayout<Int32>.size | ||
case .uint32: | ||
return MemoryLayout<UInt32>.size | ||
case .int16: | ||
return MemoryLayout<Int16>.size | ||
case .uint16: | ||
return MemoryLayout<UInt16>.size | ||
case .int8: | ||
return MemoryLayout<Int8>.size | ||
case .uint8: | ||
return MemoryLayout<UInt8>.size | ||
case .bool: | ||
return MemoryLayout<Bool>.size | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the original lib implements more dtypes, see here https://github.com/huggingface/safetensors/blob/5db3b92c76ba293a0715b916c16b113c0b3551e9/safetensors/src/tensor.rs#L656
the problem I see with this approach is that even more types can be added in future. Keeping as a string allows us to parse it without a risk that a future addition will break it. We are validating it anyway when materializing to
MLTensor
ofMLMultiArray
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have to check support for the new string types anyway so at least we have clearly defined place where to add it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let consider a scenario where a new type was added but we don't support it yet. The example file contains bunch of tensors, some of them we support, some of them we don't (they are not specified in
DType
enum). I might be wrong but using your approach user won't be able even to open the file, using the old approach user will be able to open the file and materialize the tensors we have the support forThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you see value in being able to open the file but not able to materialise it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a file can contain tensors data of multiple type, so yes, I see the value of being able to open the file and materialize the tensors we have the support for