Skip to content

LLamaSharp (0.26.0) LLamaWeights.NativeHandle.LoadLoraFromFile need read & write access to lora file #1367

@harry330

Description

@harry330

We are currently developing an AI application using LlamaSharp. For security considerations, we have a System-privileged process responsible for downloading the model and LoRA files to a designated directory. Access Control Lists (ACLs) are configured so that only the System-privileged process has read and write permissions, while user-privileged processes have read-only access. Concurrently, we have a separate process—ModelRunner—that loads the model via LlamaSharp and performs inference operations. Adhering to the principle of least privilege, we run ModelRunner with user privileges.

When ModelRunner attempts to load LoRA files using LLamaWeights.NativeHandle.LoadLoraFromFile, the operation fails. This failure occurs because ModelRunner runs with user privileges, and user privileges grant only read access to the model and LoRA files. The reason LoadLoraFromFile requires write permissions is as follows:

public LoraAdapter LoadLoraFromFile(string path)
{
  path = Path.GetFullPath(path);
  using (FileStream fileStream = new FileStream(path, **FileMode.Open**))
  {
    if (!fileStream.CanRead)
      throw new InvalidOperationException("LoRA file '" + path + "' is not readable");
  }
  IntPtr nativePtr = SafeLlamaModelHandle.llama_adapter_lora_init(this, path);
  return new LoraAdapter(this, path, nativePtr);
}
public FileStream(string path, FileMode mode)
    : this(path, mode, mode == FileMode.Append ? FileAccess.Write : **FileAccess.ReadWrite**, DefaultShare, DefaultBufferSize, DefaultIsAsync)
{
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions