Skip to content
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

instructlab 0.21.2 (new formula) #200460

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
93 changes: 93 additions & 0 deletions Formula/i/instructlab.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
class Instructlab < Formula
include Language::Python::Virtualenv

desc "Use a novel synthetic data-based alignment tuning method for LLMs"
homepage "https://github.com/instructlab/instructlab"
url "https://github.com/instructlab/instructlab/releases/download/v0.21.2/instructlab-0.21.2.tar.gz"
sha256 "99c2ba360214005088f6ee1a94d60fb89c622e78e5b6c1d8df2f67b8cbf36fd3"
license "Apache-2.0"

depends_on "ccache" => :build
Copy link
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Author

Choose a reason for hiding this comment

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

you mean why use "ccache"? I also tested from different local machines, one need, another is no need, I not sure whether missed it.

Copy link
Member

Choose a reason for hiding this comment

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

How can you tell it needs ccache?

depends_on "cmake" => :build
depends_on "pkgconf" => :build
depends_on "python@3.11"
Copy link
Member

Choose a reason for hiding this comment

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

Why not the latest?


def fix_dylib_paths(target_files: nil)
Copy link
Member

Choose a reason for hiding this comment

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

This really shouldn't be part of a formula. If this is broken it should be reported to brew and fixed there.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you so much for your feedback.This is my first time to write the formula. May I know any possible situations that will hit the Error: Failed to fix install linkage issue during the installation???
Because never hit it without brew install.

require "macho"

dylibs_path = libexec/"lib/python3.11/site-packages/PIL/.dylibs"
files_to_process = target_files || dylibs_path.glob("*.dylib")

files_to_process.each do |dylib|
next unless dylib.exist?

macho = MachO.open(dylib)

new_id = "@loader_path/#{dylib.basename}"
macho.change_dylib_id(new_id)

macho.dylib_load_commands.each do |cmd|
old_path = cmd.name.to_s
next unless old_path.include?("PIL/.dylibs")

new_path = "@loader_path/#{File.basename(old_path)}"
macho.change_install_name(old_path, new_path)
end

macho.write!

MachO.codesign!(dylib)

validation_output = `otool -L #{dylib}`
if validation_output.include?("@loader_path/#{dylib.basename}")
ohai "Successfully fixed and validated: #{dylib.basename}"
else
opoo "Validation failed for: #{dylib.basename}. Please check manually using `otool -L #{dylib}`."
end
end
end

# Fix -flat_namespace being used on Big Sur and later.
patch do
url "https://raw.githubusercontent.com/Homebrew/formula-patches/03cf8088210822aa2c1ab544ed58ea04c897d9c4/libtool/configure-big_sur.diff"
sha256 "35acd6aebc19843f1a2b3a63e880baceb0f5278ab1ace661e57a502d9d78c93c"
end
Comment on lines +50 to +54
Copy link
Member

Choose a reason for hiding this comment

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

This should be reported and fixed upstream

Copy link
Author

Choose a reason for hiding this comment

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

just hit -flat_namespace in local test, so tried to add it.

Copy link
Member

Choose a reason for hiding this comment

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

If that's the case the upstream configure script should be regenerated with a modern version of autoconf. This was fixed years ago.


def install

Check failure on line 56 in Formula/i/instructlab.rb

View workflow job for this annotation

GitHub Actions / Linux

`brew install --verbose --formula --build-bottle instructlab` failed on Linux!

::error::instructlab 0.21.2 did not build

Check failure on line 56 in Formula/i/instructlab.rb

View workflow job for this annotation

GitHub Actions / macOS 15-arm64

`brew install --verbose --formula --build-bottle instructlab` failed on macOS Sequoia (15) on Apple Silicon!

::error::instructlab 0.21.2 did not build

Check failure on line 56 in Formula/i/instructlab.rb

View workflow job for this annotation

GitHub Actions / macOS 14-arm64

`brew install --verbose --formula --build-bottle instructlab` failed on macOS Sonoma (14) on Apple Silicon!

::error::instructlab 0.21.2 did not build

Check failure on line 56 in Formula/i/instructlab.rb

View workflow job for this annotation

GitHub Actions / macOS 13-arm64

`brew install --verbose --formula --build-bottle instructlab` failed on macOS Ventura (13) on Apple Silicon!

::error::instructlab 0.21.2 did not build
odie "This tool only supports Apple Silicon (M1/M2/M3) systems. Installation aborted." unless Hardware::CPU.arm?
Copy link
Member

Choose a reason for hiding this comment

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

That should be depends_on arch: :arm then


venv = virtualenv_create(libexec, "python3.11", system_site_packages: false)
system libexec/"bin/python", "-m", "ensurepip"
system libexec/"bin/python", "-m", "pip", "install", "--upgrade", "pip", "setuptools", "wheel"
system libexec/"bin/python", "-m", "pip", "cache", "remove", "llama_cpp_python"
venv.pip_install_and_link buildpath
system libexec/"bin/python", "-m", "pip", "install", "-r", buildpath/"requirements.txt"
Copy link
Member

Choose a reason for hiding this comment

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

This is not allowed, all downloads should be resources

Copy link
Author

Choose a reason for hiding this comment

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

Could you please share a good example of this(similar with this install with pip and python project)? thanks a lot.

Copy link
Member

Choose a reason for hiding this comment

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

Anything in this repo that mentions venv will probably do exactly that.

Copy link
Author

@reidliu41 reidliu41 Dec 9, 2024

Choose a reason for hiding this comment

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

May i confirm only can use tar.gz in resources? Or the others e.g. .whl

Copy link
Member

Choose a reason for hiding this comment

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

All resources for Homebrew formula need to be built from source.

Copy link
Member

Choose a reason for hiding this comment

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

There is an mlx Homebrew formula: https://formulae.brew.sh/formula/mlx#default

Depending on Homebrew formulae means less time spent compiling dependencies (because other Homebrew formulae have already been compiled before), not more.

Copy link
Author

Choose a reason for hiding this comment

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

thanks, yeah, already used mlx formula, but also for torch and easyocr

Copy link
Author

Choose a reason for hiding this comment

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

No, more things to compile will always mean slower builds.

bottle will help to speed up to install?

Copy link

Choose a reason for hiding this comment

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

sorry, I still can see some using .whl.

  • gptme: multiprocessing-logging
  • scoutsuite: asyncio-throttle
  • pocsuite3: dacite
  • parsedmarc: events

I mean I tried many times on some packages, still failed, e.g. pydantic-core

 Compiling pydantic-core v2.23.4 (/private/tmp/instructlab--pydantic-core-20241211-55519-ki01jd/pydantic_core-2.23.4)
     Compiling yoke v0.7.4
     Compiling strum v0.26.3
  error: failed to run custom build command for pydantic-core v2.23.4 (/private/tmp/instructlab--pydantic-core-20241211-55519-ki01jd/pydantic_core-2.23.4)

  Caused by:
    process didn't exit successfully: /private/tmp/instructlab--pydantic-core-20241211-55519-ki01jd/pydantic_core-2.23.4/target/release/build/pydantic-core-a958d6f7523c4c99/build-script-build (exit status: 101)
    --- stdout
    cargo:rustc-check-cfg=cfg(Py_LIMITED_API)
    cargo:rustc-check-cfg=cfg(PyPy)
    cargo:rustc-check-cfg=cfg(GraalPy)
    cargo:rustc-check-cfg=cfg(py_sys_config, values("Py_DEBUG", "Py_REF_DEBUG", "Py_TRACE_REFS", "COUNT_ALLOCS"))
    cargo:rustc-check-cfg=cfg(invalid_from_utf8_lint)
    cargo:rustc-check-cfg=cfg(pyo3_disable_reference_pool)
    cargo:rustc-check-cfg=cfg(pyo3_leak_on_drop_without_reference_pool)
    cargo:rustc-check-cfg=cfg(diagnostic_namespace)
    cargo:rustc-check-cfg=cfg(c_str_lit)
    cargo:rustc-check-cfg=cfg(Py_3_7)
    cargo:rustc-check-cfg=cfg(Py_3_8)
    cargo:rustc-check-cfg=cfg(Py_3_9)
    cargo:rustc-check-cfg=cfg(Py_3_10)
    cargo:rustc-check-cfg=cfg(Py_3_11)
    cargo:rustc-check-cfg=cfg(Py_3_12)
    cargo:rustc-check-cfg=cfg(Py_3_13)
    cargo:rustc-cfg=Py_3_6
    cargo:rustc-cfg=Py_3_7
    cargo:rustc-cfg=Py_3_8
    cargo:rustc-cfg=Py_3_9
    cargo:rustc-cfg=Py_3_10
    cargo:rustc-cfg=Py_3_11
    cargo:rustc-check-cfg=cfg(has_coverage_attribute)
    cargo:rustc-check-cfg=cfg(specified_profile_use)
    cargo:rerun-if-changed=python/pydantic_core/core_schema.py
    cargo:rerun-if-changed=generate_self_schema.py

    --- stderr
    thread 'main' panicked at build.rs:23:6:
    failed to execute process: Os { code: 2, kind: NotFound, message: "No such file or directory" }
    stack backtrace:
       0:        0x10021b0f0 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h2260af3a60e707d0
       1:        0x100232fa4 - core::fmt::write::h40c2acd4666eb4d3
       2:        0x10022747c - std::io::Write::write_fmt::h41d6e98dca6ecc3d
       3:        0x10021afa4 - std::sys::backtrace::BacktraceLock::print::h6927682eb47cb165
       4:        0x1002133d0 - std::panicking::default_hook::{{closure}}::h3800acb1d5aa9da8
       5:        0x100213278 - std::panicking::default_hook::hdb07ba29d8151fe7
       6:        0x1002139d4 - std::panicking::rust_panic_with_hook::h3a42c361c08813d5
       7:        0x10021bb78 - std::panicking::begin_panic_handler::{{closure}}::h483101861bc4cead
       8:        0x10021b348 - std::sys::backtrace::__rust_end_short_backtrace::he99aa938f9475e2a
       9:        0x100213460 - _rust_begin_unwind
      10:        0x10023a6c0 - core::panicking::panic_fmt::h5a90ea35d2c8d236
      11:        0x10023a5f4 - core::result::unwrap_failed::h1004b19edf1ee39c
      12:        0x1001c5e4c - core::result::Result<T,E>::expect::h3cfa09ac261c995d
                                   at /private/tmp/rust-20241128-8290-tgv7i0/rustc-1.83.0-src/library/core/src/result.rs:1061:23
      13:        0x1001c6330 - build_script_build::generate_self_schema::h8998121fd627a745
                                   at /private/tmp/instructlab--pydantic-core-20241211-55519-ki01jd/pydantic_core-2.23.4/build.rs:15:18
      14:        0x1001c683c - build_script_build::main::h3408e214aa52d7ff
                                   at /private/tmp/instructlab--pydantic-core-20241211-55519-ki01jd/pydantic_core-2.23.4/build.rs:48:5
      15:        0x1001c5b74 - core::ops::function::FnOnce::call_once::h11534ba8fc470188
                                   at /private/tmp/rust-20241128-8290-tgv7i0/rustc-1.83.0-src/library/core/src/ops/function.rs:250:5
      16:        0x1001c5974 - std::sys::backtrace::__rust_begin_short_backtrace::h9308af8abe66a92e
                                   at /private/tmp/rust-20241128-8290-tgv7i0/rustc-1.83.0-src/library/std/src/sys/backtrace.rs:154:18
      17:        0x1001c590c - std::rt::lang_start::{{closure}}::h1e4794855c4666b3
                                   at /private/tmp/rust-20241128-8290-tgv7i0/rustc-1.83.0-src/library/std/src/rt.rs:195:18
      18:        0x10020c31c - std::rt::lang_start_internal::hadea728b8c40134b
      19:        0x1001c58d8 - std::rt::lang_start::h055df2df94d70e77
                                   at /private/tmp/rust-20241128-8290-tgv7i0/rustc-1.83.0-src/library/std/src/rt.rs:194:17
      20:        0x1001c69d4 - _main
  warning: build failed, waiting for other jobs to finish...
  💥 maturin failed
    Caused by: Failed to build a native library through cargo
    Caused by: Cargo build finished with "exit status: 101": env -u CARGO MACOSX_DEPLOYMENT_TARGET="11.0" PYO3_ENVIRONMENT_SIGNATURE="cpython-3.11-64bit" PYO3_PYTHON="/opt/homebrew/Cellar/instructlab/0.21.2/libexec/bin/python" PYTHON_SYS_EXECUTABLE="/opt/homebrew/Cellar/instructlab/0.21.2/libexec/bin/python" "cargo" "rustc" "--features" "pyo3/extension-module" "--message-format" "json-render-diagnostics" "--manifest-path" "/private/tmp/instructlab--pydantic-core-20241211-55519-ki01jd/pydantic_core-2.23.4/Cargo.toml" "--release" "--lib" "--crate-type" "cdylib" "--" "-C" "link-arg=-undefined" "-C" "link-arg=dynamic_lookup" "-C" "link-args=-Wl,-install_name,@rpath/pydantic_core._pydantic_core.cpython-311-darwin.so"
  Error: command ['maturin', 'pep517', 'build-wheel', '-i', '/opt/homebrew/Cellar/instructlab/0.21.2/libexec/bin/python', '--compatibility', 'off'] returned non-zero exit status 1
  error: subprocess-exited-with-error

  × Building wheel for pydantic_core (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> See above for output.

  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: /opt/homebrew/Cellar/instructlab/0.21.2/libexec/bin/python /opt/homebrew/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py build_wheel /private/tmp/tmp1j6kzjhh
  cwd: /private/tmp/instructlab--pydantic-core-20241211-55519-ki01jd/pydantic_core-2.23.4
  Building wheel for pydantic_core (pyproject.toml): finished with status 'error'
  ERROR: Failed building wheel for pydantic_core
Failed to build pydantic_core
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (pydantic_core)
/usr/bin/env /opt/homebrew/Library/Homebrew/shims/shared/curl --version
/opt/homebrew/Library/Homebrew/ignorable.rb:27:in block in raise'
BuildError: Failed executing: python3.11 -m pip --python=/opt/homebrew/Cellar/instructlab/0.21.2/libexec/bin/python install --verbose --no-deps --no-binary=:all: --ignore-installed --no-compile /private/tmp/instructlab--pydantic-core-20241211-55519-ki01jd/pydantic_core-2.23.4
1. raise
2. ignore
3. backtrace
4. irb
5. shell
Choose an action:

so I would like to try .whl,
but the weird thing is that my test is failed for ERROR: Directory '/private/tmp/instructlab--pydantic-core-20241211-40347-vjaz8v' is not installable. Neither 'setup.py' nor 'pyproject.toml' found.

if you have any ideas, feel free to share, thanks a lot.

Copy link
Member

Choose a reason for hiding this comment

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

sorry, I still can see some using .whl.

  • gptme: multiprocessing-logging
  • scoutsuite: asyncio-throttle
  • pocsuite3: dacite
  • parsedmarc: events

This is only accepted when the .whl is tagged as py3-none-any and if there are no sdists (.tar.gzs) available on PyPI.


# Replace universal binaries with native slices.
deuniversalize_machos
Comment on lines +66 to +67
Copy link
Member

Choose a reason for hiding this comment

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

Why is it building universal binaries if it doesn't support non ARM?

end

def post_install
# Fix dynamic library paths in PIL dependencies
fix_dylib_paths(target_files: [libexec/"lib/python3.11/site-packages/PIL/.dylibs/libpng16.16.dylib"])

# Installation success message
Copy link
Member

Choose a reason for hiding this comment

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

This should be a caveat if it's specific to Homebrew and removed if it's not

Copy link
Author

Choose a reason for hiding this comment

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

yeah, I tried caveat, but it is strange, it called twice at the end..

ohai "✅ InstructLab has been installed successfully."
ohai "Next Steps:"
ohai " Run `ilab config init` to initialize your configuration."
ohai "Use `ilab --help` to get started."
end

test do
# check dylibs
dylibs_path = libexec/"lib/python3.11/site-packages/PIL/.dylibs"

dylib_path = dylibs_path/"libpng16.16.dylib"
Copy link
Member

Choose a reason for hiding this comment

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

We should use Homebrew libpng instead of vendoring a different one.

if dylib_path.exist?
otool_output = shell_output("otool -L #{dylib_path}")
assert_match "@loader_path/libpng16.16.dylib", otool_output, "Incorrect or missing path in dylib linkage"
end
# Verify installation and functionality of the CLI tool
assert_match "Usage:", shell_output("#{bin}/ilab --help")
EricFromCanada marked this conversation as resolved.
Show resolved Hide resolved
end
end
Loading