-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from coreweave/es/te-base-flash-attn
feat(torch): Update `TransformerEngine` to v1.11 & move `flash-attn`
- Loading branch information
Showing
3 changed files
with
146 additions
and
58 deletions.
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
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,76 @@ | ||
PROGRAM compiler_wrapper | ||
! Wraps GCC invocations, | ||
! replacing -D__AVX512__ and -D__SCALAR__ preprocessor definitions | ||
! with -D__AVX256__, and -march=native with -march=skylake, | ||
! for better reproducibility and compatibility. | ||
IMPLICIT NONE | ||
INTEGER :: i, exitcode = 0, full_length = 0, truncated = 0 | ||
CHARACTER(len=:), ALLOCATABLE :: arg, command | ||
ALLOCATE(CHARACTER(len=128) :: arg) | ||
command = "gcc" | ||
|
||
DO i = 1, COMMAND_ARGUMENT_COUNT() | ||
DO | ||
CALL GET_COMMAND_ARGUMENT(i, arg, full_length, truncated) | ||
IF (truncated == 0) THEN | ||
EXIT | ||
ELSE IF (truncated == -1) THEN | ||
DEALLOCATE(arg) | ||
ALLOCATE(CHARACTER(len=full_length) :: arg) | ||
ELSE | ||
CALL EXIT(95) | ||
END IF | ||
END DO | ||
IF (arg == "-march=native") THEN | ||
command = command // " '-march=skylake'" | ||
ELSE IF (arg == "-D__AVX512__" .OR. arg == "-D__SCALAR__") THEN | ||
command = command // " '-D__AVX256__'" | ||
ELSE | ||
command = command // shell_escaped(arg) | ||
END IF | ||
END DO | ||
CALL SYSTEM(command, exitcode) | ||
IF (exitcode > 255) THEN | ||
exitcode = MAX(IAND(exitcode, 255), 1) | ||
END IF | ||
CALL EXIT(exitcode) | ||
|
||
|
||
CONTAINS | ||
FUNCTION shell_escaped(str) RESULT(out) | ||
! Turns [str] into [ 'str'] and replaces all | ||
! internal ['] characters with ['"'"'] | ||
IMPLICIT NONE | ||
CHARACTER(len=*), INTENT(IN) :: str | ||
CHARACTER(len=:), ALLOCATABLE :: out | ||
INTEGER :: old_i, out_i, old_len, out_len | ||
|
||
old_len = LEN_TRIM(str) | ||
! Figure out the new length to allocate by scanning `str`. | ||
! This always needs to add at least [ '] at the beginning | ||
! and ['] at the end, so the length increases by at least 3. | ||
out_len = old_len + 3 | ||
DO old_i = 1, old_len | ||
IF (str(old_i:old_i) == "'") THEN | ||
out_len = out_len + 4 | ||
END IF | ||
END DO | ||
ALLOCATE(CHARACTER(len=out_len) :: out) | ||
|
||
! Copy over the string, performing necessary escapes. | ||
out(1:2) = " '" | ||
out_i = 3 | ||
DO old_i = 1, old_len | ||
IF (str(old_i:old_i) == "'") THEN | ||
! Escape internal single-quotes | ||
out(out_i:out_i + 4) = '''"''"''' | ||
out_i = out_i + 5 | ||
ELSE | ||
! No escaping needed | ||
out(out_i:out_i) = str(old_i:old_i) | ||
out_i = out_i + 1 | ||
END IF | ||
END DO | ||
out(out_i:out_i) = "'" | ||
END FUNCTION | ||
END PROGRAM |