| 1 | package Langertha::VLLMHook::Config; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Loader for vLLM-Hook model_configs/*.json files | ||||||||||||||||||||||||||||
| 3 | 2 | our $VERSION = '0.505'; | |||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use JSON::MaybeXS (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | with 'Langertha::Role::JSON'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 2 | has file => ( | |||||||||||||||||||||||||||
| 12 | is => 'ro', | ||||||||||||||||||||||||||||
| 13 | isa => 'Str', | ||||||||||||||||||||||||||||
| 14 | predicate => 'has_file', | ||||||||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | has data => ( | |||||||||||||||||||||||||||
| 19 | is => 'ro', | ||||||||||||||||||||||||||||
| 20 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 21 | lazy_build => 1, | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub _build_data { | ||||||||||||||||||||||||||
|
Subroutine
_build_data: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 24 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 25 | 0 | ▶ | croak "Langertha::VLLMHook::Config requires 'file' or 'data'" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | unless $self->has_file; | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | open my $fh, '<:raw', $self->file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | or croak "Langertha::VLLMHook::Config cannot open '".$self->file."': $!"; | ||||||||||||||||||||||||||||
| 29 | 0 | local $/; | |||||||||||||||||||||||||||
| 30 | 0 | my $content = <$fh>; | |||||||||||||||||||||||||||
| 31 | 0 | close $fh; | |||||||||||||||||||||||||||
| 32 | 0 | return $self->json->decode($content); | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 5 | ▶ | sub worker { | ||||||||||||||||||||||||||
|
Subroutine
worker: called CC=8 SCAR=21.2
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 5 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 39 | 5 | my $cfg = $self->data; | |||||||||||||||||||||||||||
| 40 | 5 | ▶ | return 'steer' if ref $cfg->{steering} eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 4 | ▶ | return 'hidden_states' if ref $cfg->{hidden_states} eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | return 'qk' if ref $cfg->{params} eq 'HASH' | ||||||||||||||||||||||||||||
| 43 | 2 | ▶ | && exists $cfg->{params}{important_heads}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $$cfg{"params"} eq "HASH" and exists $$cfg{"params"}{"important_heads"}
MC/DC50%1/2
ref $$cfg{"params"} eq "HASH" and exists $$cfg{"params"}{"important_heads"}
ref $$cfg{"params"} eq "HASH"
exists $$cfg{"params"}{"important_heads"}
Truth table66%2/3
A and B
A= ref $$cfg{"params"} eq "HASH"B= exists $$cfg{"params"}{"important_heads"}
| |||||||||||||||||||||||||||||
| 44 | 1 | ▶ | my $provider = $cfg->{model_info} ? ( $cfg->{model_info}{provider} // '' ) : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$$cfg{"model_info"}{"provider"} // ""
MC/DC0%0/1
$$cfg{"model_info"}{"provider"} // ""
$$cfg{"model_info"}{"provider"}
Truth table50%1/2
A
A= $$cfg{"model_info"}{"provider"}
| |||||||||||||||||||||||||||||
| 45 | 1 | ▶ | return 'qk' if $provider =~ /attn/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 1 | return undef; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 2 | ▶ | sub model_id { | ||||||||||||||||||||||||||
|
Subroutine
model_id: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 2 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 52 | 2 | ▶ | my $info = $self->data->{model_info} or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 2 | return $info->{model_id}; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 5 | ▶ | sub xargs { | ||||||||||||||||||||||||||
|
Subroutine
xargs: called CC=10 SCAR=23.2
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 5 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 59 | 5 | my $cfg = $self->data; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 5 | ▶ | if ( ref $cfg->{steering} eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 1 | return { steer => $self->encode_json_text( $cfg->{steering} ) }; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 4 | ▶ | if ( ref $cfg->{hidden_states} eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 2 | my $layers = $cfg->{hidden_states}{layers}; | |||||||||||||||||||||||||||
| 67 | 2 | ▶ | if ( ref $layers eq 'ARRAY' && @$layers ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $layers eq "ARRAY" and @$layers
MC/DC50%1/2
ref $layers eq "ARRAY" and @$layers
ref $layers eq "ARRAY"
@$layers
Truth table66%2/3
A and B
A= ref $layers eq "ARRAY"B= @$layers
| |||||||||||||||||||||||||||||
| 68 | 1 | return { output_hidden_states => $self->encode_json_text($layers) }; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | 1 | return { output_hidden_states => JSON::MaybeXS::true() }; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 2 | ▶ | if ( ref $cfg->{params} eq 'HASH' && $cfg->{params}{important_heads} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $$cfg{"params"} eq "HASH" and $$cfg{"params"}{"important_heads"}
MC/DC50%1/2
ref $$cfg{"params"} eq "HASH" and $$cfg{"params"}{"important_heads"}
ref $$cfg{"params"} eq "HASH"
$$cfg{"params"}{"important_heads"}
Truth table66%2/3
A and B
A= ref $$cfg{"params"} eq "HASH"B= $$cfg{"params"}{"important_heads"}
| |||||||||||||||||||||||||||||
| 74 | 1 | my %layer_to_heads; | |||||||||||||||||||||||||||
| 75 | 1 | for my $pair ( @{ $cfg->{params}{important_heads} } ) { | |||||||||||||||||||||||||||
| 76 | 4 | my ( $layer, $head ) = @$pair; | |||||||||||||||||||||||||||
| 77 | 4 | push @{ $layer_to_heads{$layer} }, $head; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | 1 | ▶ | my $mode = $cfg->{hookq} ? ( $cfg->{hookq}{hookq_mode} // 'last_token' ) : 'last_token'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$$cfg{"hookq"}{"hookq_mode"} // "last_token"
MC/DC0%0/1
$$cfg{"hookq"}{"hookq_mode"} // "last_token"
$$cfg{"hookq"}{"hookq_mode"}
Truth table50%1/2
A
A= $$cfg{"hookq"}{"hookq_mode"}
| |||||||||||||||||||||||||||||
| 80 | return { | ||||||||||||||||||||||||||||
| 81 | 1 | output_qk => $self->encode_json_text( \%layer_to_heads ), | |||||||||||||||||||||||||||
| 82 | hookq_mode => $mode, | ||||||||||||||||||||||||||||
| 83 | }; | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 1 | return {}; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 2 | 1; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | __END__ | ||||||||||||||||||||||||||||