Can't write a model in submitted code

in my train function, when I submit, I tried joblib.dump(model, f"{Constants.MODEL_DIRECTORY}/model.joblib"); it said the directory doesn’t exist.

When I added os.makedirs(Constants.MODEL_DIRECTORY, exist_ok=True) it says I don’t have permission.

Help is greatly appreciated.

From the logs I can see that your constant is defined as ./model_directory.

While in the runner, only the resources/ directory is writable, and I suggest you always take it from the model_directory_path variable.

Changing code is hard, so you could just change your constant’s value first thing in a function:

class Constants:
    MODEL_DIRECTORY = "./model_directory"


def train(
    ...,
    model_directory_path: str,
):
    Constants.MODEL_DIRECTORY = model_directory_path
    ...


def infer(
    ...,
    model_directory_path: str,
):
    Constants.MODEL_DIRECTORY = model_directory_path
    ...

    yield
    ...

I have tried changing my code; both as you suggest (using a variable in constant), and resetting the value to model directory, or just calling dump(model_directory; still no dice.) (directory does not exist).

What to do? Try using an explicit path that include ./resources?)

Thanks for your help. Is there an example around that computes a model in the model phase, saves it, and restores it in infer.

Parameters with default value are ignored:

train: skip param with default value: model_directory_path=./model_directory

So you were overwriting the value.
This warning is visible if you enable advanced logs, but should still visible when running a local test.
Don’t set any value and let the system provide it for you.

def train(
    ...,
    model_directory_path: str,  # DON'T SET A DEFAULT VALUE!!
):
    Constants.MODEL_DIRECTORY = model_directory_path
    ...

On another note, I just saw that you did not upload any resources directory with your submission, so you could have just changed the constant’s value to be ./resources directly.

thank you, I finally got this working