Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion third_party/amd/backend/driver.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#define PY_SSIZE_T_CLEAN
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you only want to fix this file, why trigger other changes?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't understand

For python 3.12 and older, the macro PY_SSIZE_T_CLEAN must be defined before including Python.h to use all # variants of formats (s#, y#, etc.).

Isn't is already defined before Python.h here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do clean up your PR

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I unintentionally formatted the python files by mistake, I have removed the unwanted changes.

Regarding your second question, yes it was defined before Python.h, but the error was still present (unsloth version '2025.5.7').

My understanding is that the error was due #include statements written before PY_SSIZE_T_CLEAN was defined, as per the system error message PY_SSIZE_T_CLEAN macro must be defined for '#' forma.

Defining it on top of the file removed the error for me (on python 3.12.10).

Copy link
Copy Markdown
Contributor

@Jokeren Jokeren May 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you did is not consistent with your comment

For python 3.12 and older, the macro PY_SSIZE_T_CLEAN must be defined before including Python.h to use all # variants of formats (s#, y#, etc.).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bug seems to still exist. The macro must also be defined in the embedded C source code defined in driver.py, in the make_lanucher function, line 229:

` params.append("&global_scratch")
src = f"""
#include "cuda.h"
#include <stdbool.h>
#include <Python.h>
#include <dlfcn.h>

`
PY_SSIZE_T_CLEAN is not defined before Python.h is included.

#define __HIP_PLATFORM_AMD__
// clang-format off
// hip_depreated.h needs definitions from hip_runtime.h.
#include <hip/hip_runtime.h>
#include <hip/hip_deprecated.h>
// clang-format on
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <dlfcn.h>
#include <stdio.h>
Expand Down
1 change: 1 addition & 0 deletions third_party/amd/backend/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ def format_of(ty):
params = [f"&arg{i}" for i, ty in signature.items() if ty != "constexpr"]
params.append("&global_scratch")
src = f"""
#define PY_SSIZE_T_CLEAN
#define __HIP_PLATFORM_AMD__
#include <hip/hip_runtime.h>
#include <Python.h>
Expand Down
4 changes: 2 additions & 2 deletions third_party/nvidia/backend/driver.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#define PY_SSIZE_T_CLEAN
#include "cuda.h"
#include <Python.h>
#include <dlfcn.h>
#include <stdbool.h>
#define PY_SSIZE_T_CLEAN
#include <Python.h>

// Raises a Python exception and returns false if code is not CUDA_SUCCESS.
static bool gpuAssert(CUresult code, const char *file, int line) {
Expand Down
1 change: 1 addition & 0 deletions third_party/nvidia/backend/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def format_of(ty):
params = [f"&arg{i}" for i, ty in signature.items() if ty != "constexpr"]
params.append("&global_scratch")
src = f"""
#define PY_SSIZE_T_CLEAN
#include \"cuda.h\"
#include <stdbool.h>
#include <Python.h>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like the only change that is likely to make any difference. All the other cases already defined the macro before including Python.h.

Expand Down
Loading